From d71d3b4aaa995681a20207d72cf3b6ac9c3d72c0 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 7 Nov 2015 13:33:26 -0800 Subject: 2388 - final layer of edit/ loaded successfully --- 020run.cc | 1 + 031address.cc | 7 +++++ 059generic_recipe.cc | 22 ++++++++++++--- edit/011-editor-undo.mu | 73 ++++++++++++++++++++++++------------------------- 4 files changed, 62 insertions(+), 41 deletions(-) diff --git a/020run.cc b/020run.cc index 42b11fc2..fad6a5b0 100644 --- a/020run.cc +++ b/020run.cc @@ -155,6 +155,7 @@ if (argc > 1) { transform_all(); //? dump_recipe("handle-keyboard-event"), exit(0); if (Run_tests) Recipe.erase(get(Recipe_ordinal, string("main"))); + // End Loading .mu Files } //: Step 3: if we aren't running tests, locate a recipe called 'main' and diff --git a/031address.cc b/031address.cc index 306621f1..c4b260d1 100644 --- a/031address.cc +++ b/031address.cc @@ -92,6 +92,13 @@ void drop_address_from_type(reagent& r) { r.type = tmp->right; tmp->right = NULL; delete tmp; + // property + if (r.properties.at(0).second) { + string_tree* tmp2 = r.properties.at(0).second; + r.properties.at(0).second = tmp2->right; + tmp2->right = NULL; + delete tmp2; + } } void drop_one_lookup(reagent& r) { diff --git a/059generic_recipe.cc b/059generic_recipe.cc index 7b0ef162..64dbf6a1 100644 --- a/059generic_recipe.cc +++ b/059generic_recipe.cc @@ -34,6 +34,13 @@ recipe foo a:_t -> result:_t [ :(after "void check_header_products(const recipe_ordinal r)") if (any_type_ingredient_in_header(r)) return; +//: We'll be creating recipes without loading them from anywhere by +//: *specializing* existing recipes, so make sure we don't clear any of those +//: when we start running tests. +:(before "End Loading .mu Files") +recently_added_recipes.clear(); +recently_added_types.clear(); + :(before "End Instruction Dispatch(inst, best_score)") if (best_score == -1) { trace(9992, "transform") << "no variant found; searching for variant with suitable type ingredients" << end(); @@ -150,15 +157,21 @@ recipe_ordinal new_variant(recipe_ordinal exemplar, const instruction& inst) { } void compute_type_ingredient_mappings(const recipe& exemplar, const instruction& inst, map& mappings) { +//? cerr << "=== " << exemplar.name << " vs " << inst.to_string() << '\n'; for (long long int i = 0; i < SIZE(exemplar.ingredients); ++i) { - accumulate_type_ingredients(exemplar.ingredients.at(i), inst.ingredients.at(i), mappings, exemplar); + reagent ingredient = inst.ingredients.at(i); + canonize_type(ingredient); + accumulate_type_ingredients(exemplar.ingredients.at(i), ingredient, mappings, exemplar); } for (long long int i = 0; i < SIZE(exemplar.products); ++i) { - accumulate_type_ingredients(exemplar.products.at(i), inst.products.at(i), mappings, exemplar); + reagent product = inst.products.at(i); + canonize_type(product); + accumulate_type_ingredients(exemplar.products.at(i), product, mappings, exemplar); } } void accumulate_type_ingredients(const reagent& base, const reagent& refinement, map& mappings, const recipe& exemplar) { +//? cerr << base.to_string() << " vs " << refinement.to_string() << '\n'; if (!refinement.properties.at(0).second) { if (!Trace_stream) cerr << "Turn on START_TRACING_UNTIL_END_OF_SCOPE in 020run.cc for more details.\n"; DUMP(""); @@ -177,10 +190,11 @@ void accumulate_type_ingredients(const string_tree* base, const string_tree* ref assert(!refinement->value.empty()); if (!contains_key(mappings, base->value)) { trace(9993, "transform") << "adding mapping from " << base->value << " to " << refinement->value << end(); - mappings[base->value] = refinement->value; + put(mappings, base->value, refinement->value); } else { - assert(mappings[base->value] == refinement->value); +//? cerr << base->value << ": " << get(mappings, base->value) << " => " << refinement->value << '\n'; + assert(get(mappings, base->value) == refinement->value); } } else { diff --git a/edit/011-editor-undo.mu b/edit/011-editor-undo.mu index 9f0d83de..655d30fb 100644 --- a/edit/011-editor-undo.mu +++ b/edit/011-editor-undo.mu @@ -11,13 +11,13 @@ exclusive-container operation [ container insert-operation [ before-row:number before-column:number - before-top-of-screen:address:duplex-list:character:character + before-top-of-screen:address:duplex-list:character after-row:number after-column:number - after-top-of-screen:address:duplex-list:character:character + after-top-of-screen:address:duplex-list:character # inserted text is from 'insert-from' until 'insert-until'; list doesn't have to terminate - insert-from:address:duplex-list:character:character - insert-until:address:duplex-list:character:character + insert-from:address:duplex-list:character + insert-until:address:duplex-list:character tag:number # event causing this operation; might be used to coalesce runs of similar events # 0: no coalesce (enter+indent) # 1: regular alphanumeric characters @@ -26,10 +26,10 @@ container insert-operation [ container move-operation [ before-row:number before-column:number - before-top-of-screen:address:duplex-list:character:character + before-top-of-screen:address:duplex-list:character after-row:number after-column:number - after-top-of-screen:address:duplex-list:character:character + after-top-of-screen:address:duplex-list:character tag:number # event causing this operation; might be used to coalesce runs of similar events # 0: no coalesce (touch events, etc) # 1: left arrow @@ -41,13 +41,13 @@ container move-operation [ container delete-operation [ before-row:number before-column:number - before-top-of-screen:address:duplex-list:character:character + before-top-of-screen:address:duplex-list:character after-row:number after-column:number - after-top-of-screen:address:duplex-list:character:character - deleted-text:address:duplex-list:character:character - delete-from:address:duplex-list:character:character - delete-until:address:duplex-list:character:character + after-top-of-screen:address:duplex-list:character + deleted-text:address:duplex-list:character + delete-from:address:duplex-list:character + delete-until:address:duplex-list:character tag:number # event causing this operation; might be used to coalesce runs of similar events # 0: no coalesce (ctrl-k, ctrl-u) # 1: backspace @@ -65,12 +65,12 @@ after [ { undo?:boolean <- equal *c, 26/ctrl-z break-unless undo? - undo:address:address:list <- get-address *editor, undo:offset + undo:address:address:list:address:operation <- get-address *editor, undo:offset break-unless *undo - op:address:operation/skiptypecheck <- first *undo + op:address:operation <- first *undo *undo <- rest *undo - redo:address:address:list <- get-address *editor, redo:offset - *redo/skiptypecheck <- push op, *redo + redo:address:address:list:address:operation <- get-address *editor, redo:offset + *redo <- push op, *redo reply screen/same-as-ingredient:0, editor/same-as-ingredient:1, 1/go-render } @@ -81,12 +81,12 @@ after [ { redo?:boolean <- equal *c, 25/ctrl-y break-unless redo? - redo:address:address:list <- get-address *editor, redo:offset + redo:address:address:list:address:operation <- get-address *editor, redo:offset break-unless *redo - op:address:operation/skiptypecheck <- first *redo + op:address:operation <- first *redo *redo <- rest *redo - undo:address:address:list <- get-address *editor, undo:offset - *undo/skiptypecheck <- push op, *undo + undo:address:address:list:address:operation <- get-address *editor, undo:offset + *undo <- push op, *undo reply screen/same-as-ingredient:0, editor/same-as-ingredient:1, 1/go-render } @@ -140,11 +140,11 @@ after [ ] before [ top-after:address:duplex-list:character <- get *editor, top-of-screen:offset - undo:address:address:list <- get-address *editor, undo:offset + undo:address:address:list:address:operation <- get-address *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless *undo - op:address:operation/skiptypecheck <- first *undo + op:address:operation <- first *undo typing:address:insert-operation <- maybe-convert *op, typing:variant break-unless typing previous-coalesce-tag:number <- get *typing, tag:offset @@ -155,7 +155,7 @@ before [ *after-row <- copy *cursor-row after-column:address:number <- get-address *typing, after-column:offset *after-column <- copy *cursor-column - after-top:address:address:duplex-list:character:character <- get-address *typing, after-top-of-screen:offset + after-top:address:address:duplex-list:character <- get-address *typing, after-top-of-screen:offset *after-top <- get *editor, top-of-screen:offset break +done-adding-insert-operation:label } @@ -189,12 +189,11 @@ before [ # redo stack, because it's now obsolete. # Beware: since we're counting cursor moves as operations, this means just # moving the cursor can lose work on the undo stack. -recipe add-operation [ +recipe add-operation editor:address:editor-data, op:address:operation -> editor:address:editor-data [ local-scope - editor:address:editor-data <- next-ingredient - op:address:operation <- next-ingredient + load-ingredients undo:address:address:list:address:operation <- get-address *editor, undo:offset - *undo/skiptypecheck <- push op *undo + *undo <- push op *undo redo:address:address:list:address:operation <- get-address *editor, redo:offset *redo <- copy 0 reply editor/same-as-ingredient:0 @@ -713,9 +712,9 @@ before [ break-unless undo-coalesce-tag # if previous operation was also a move, and also had the same coalesce # tag, coalesce with it - undo:address:address:list <- get-address *editor, undo:offset + undo:address:address:list:address:operation <- get-address *editor, undo:offset break-unless *undo - op:address:operation/skiptypecheck <- first *undo + op:address:operation <- first *undo move:address:move-operation <- maybe-convert *op, move:variant break-unless move previous-coalesce-tag:number <- get *move, tag:offset @@ -725,7 +724,7 @@ before [ *after-row <- copy after-cursor-row after-column:address:number <- get-address *move, after-column:offset *after-column <- copy after-cursor-column - after-top:address:address:duplex-list:character:character <- get-address *move, after-top-of-screen:offset + after-top:address:address:duplex-list:character <- get-address *move, after-top-of-screen:offset *after-top <- get *editor, top-of-screen:offset break +done-adding-move-operation:label } @@ -1596,11 +1595,11 @@ before [ { break-unless backspaced-cell # backspace failed; don't add an undo operation top-after:address:duplex-list:character <- get *editor, top-of-screen:offset - undo:address:address:list <- get-address *editor, undo:offset + undo:address:address:list:address:operation <- get-address *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless *undo - op:address:operation/skiptypecheck <- first *undo + op:address:operation <- first *undo deletion:address:delete-operation <- maybe-convert *op, delete:variant break-unless deletion previous-coalesce-tag:number <- get *deletion, tag:offset @@ -1615,7 +1614,7 @@ before [ *after-row <- copy *cursor-row after-column:address:number <- get-address *deletion, after-column:offset *after-column <- copy *cursor-column - after-top:address:address:duplex-list:character:character <- get-address *deletion, after-top-of-screen:offset + after-top:address:address:duplex-list:character <- get-address *deletion, after-top-of-screen:offset *after-top <- get *editor, top-of-screen:offset break +done-adding-backspace-operation:label } @@ -1818,11 +1817,11 @@ before [ { break-unless deleted-cell # delete failed; don't add an undo operation top-after:address:duplex-list:character <- get *editor, top-of-screen:offset - undo:address:address:list <- get-address *editor, undo:offset + undo:address:address:list:address:operation <- get-address *editor, undo:offset { # if previous operation was an insert, coalesce this operation with it break-unless *undo - op:address:operation/skiptypecheck <- first *undo + op:address:operation <- first *undo deletion:address:delete-operation <- maybe-convert *op, delete:variant break-unless deletion previous-coalesce-tag:number <- get *deletion, tag:offset @@ -1836,7 +1835,7 @@ before [ *after-row <- copy *cursor-row after-column:address:number <- get-address *deletion, after-column:offset *after-column <- copy *cursor-column - after-top:address:address:duplex-list:character:character <- get-address *deletion, after-top-of-screen:offset + after-top:address:address:duplex-list:character <- get-address *deletion, after-top-of-screen:offset *after-top <- get *editor, top-of-screen:offset break +done-adding-delete-operation:label } @@ -1941,7 +1940,7 @@ before [ { break-unless deleted-cells # delete failed; don't add an undo operation top-after:address:duplex-list:character <- get *editor, top-of-screen:offset - undo:address:address:list <- get-address *editor, undo:offset + undo:address:address:list:address:operation <- get-address *editor, undo:offset op:address:operation <- new operation:type deleted-until:address:duplex-list:character <- next-duplex *before-cursor *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, *cursor-row/after, *cursor-column/after, top-after, deleted-cells/deleted, *before-cursor/delete-from, deleted-until, 0/never-coalesce @@ -2042,7 +2041,7 @@ before [ { break-unless deleted-cells # delete failed; don't add an undo operation top-after:address:duplex-list:character <- get *editor, top-of-screen:offset - undo:address:address:list <- get-address *editor, undo:offset + undo:address:address:list:address:operation <- get-address *editor, undo:offset op:address:operation <- new operation:type deleted-until:address:duplex-list:character <- next-duplex *before-cursor *op <- merge 2/delete-operation, save-row/before, save-column/before, top-before, *cursor-row/after, *cursor-column/after, top-after, deleted-cells/deleted, *before-cursor/delete-from, deleted-until, 0/never-coalesce -- cgit 1.4.1-2-gfad0