From 8b9e9fb152924809de53a9d5bd85a12df728cceb Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 25 Jun 2015 00:19:37 -0700 Subject: 1648 --- 011load.cc | 2 ++ 041name.cc | 3 ++- edit.mu | 34 ++++++++++++++++++++++++++-------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/011load.cc b/011load.cc index 158e4b10..35a5daac 100644 --- a/011load.cc +++ b/011load.cc @@ -113,6 +113,8 @@ bool next_instruction(istream& in, instruction* curr) { ++p; // skip <- } + if (p == words.end()) + raise << "instruction prematurely ended with '<-'\n" << die(); curr->name = *p; if (Recipe_number.find(*p) == Recipe_number.end()) { Recipe_number[*p] = Next_recipe_number++; diff --git a/041name.cc b/041name.cc index e2c1d940..f87b1868 100644 --- a/041name.cc +++ b/041name.cc @@ -225,7 +225,8 @@ if (inst.operation == Recipe_number["get"] // at least 2 args, and second arg is offset assert(SIZE(inst.ingredients) >= 2); //? cout << inst.ingredients.at(1).to_string() << '\n'; //? 1 - assert(is_literal(inst.ingredients.at(1))); + if (!is_literal(inst.ingredients.at(1))) + raise << inst.to_string() << ": expected literal; got " << inst.ingredients.at(1).to_string() << '\n' << die(); if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { // since first non-address in base type must be a container, we don't have to canonize type_number base_type = skip_addresses(inst.ingredients.at(0).types); diff --git a/edit.mu b/edit.mu index 4c63f1aa..64b68582 100644 --- a/edit.mu +++ b/edit.mu @@ -320,14 +320,13 @@ recipe move-cursor-in-editor [ default-space:address:array:location <- new location:type, 30:literal editor:address:editor-data <- next-ingredient t:touch-event <- next-ingredient - row:address:number <- get-address editor:address:editor-data/deref, cursor-row:offset - row:address:number/deref <- get t:touch-event, row:offset - column:address:number <- get-address editor:address:editor-data/deref, cursor-column:offset - column:address:number/deref <- get t:touch-event, column:offset - # clear cursor pointer; will be set correctly during render - cursor:address:address:duplex-list <- get-address editor:address:editor-data/deref, before-cursor:offset - cursor:address:address:duplex-list/deref <- copy 0:literal + # update cursor + cursor-row:address:number <- get-address editor:address:editor-data/deref, cursor-row:offset + cursor-row:address:number/deref <- get t:touch-event, row:offset + cursor-column:address:number <- get-address editor:address:editor-data/deref, cursor-column:offset + cursor-column:address:number/deref <- get t:touch-event, column:offset render editor:address:editor-data + reply editor:address:editor-data/same-as-ingredient:0 ] recipe insert-at-cursor [ @@ -339,6 +338,9 @@ recipe insert-at-cursor [ #? $print before-cursor:address:address:duplex-list/deref, [ ], d:address:duplex-list, [ #? ] #? 1 insert-duplex c:character, before-cursor:address:address:duplex-list/deref + # update cursor + cursor-column:address:number <- get-address editor:address:editor-data/deref, cursor-column:offset + cursor-column:address:number/deref <- add cursor-column:address:number/deref, 1:literal render editor:address:editor-data reply editor:address:editor-data/same-as-ingredient:0 ] @@ -379,7 +381,7 @@ scenario editor-handles-mouse-clicks [ ] ] -scenario editor-inserts-keys-at-cursor [ +scenario editor-inserts-characters-at-cursor [ assume-screen 10:literal/width, 5:literal/height assume-console [ type [0] @@ -397,6 +399,22 @@ scenario editor-inserts-keys-at-cursor [ ] ] +scenario editor-moves-cursor-after-inserting-characters [ + assume-screen 10:literal/width, 5:literal/height + assume-console [ + type [01] + ] + run [ + 1:address:array:character <- new [abc] + 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right + event-loop screen:address, console:address, 2:address:editor-data + ] + screen-should-contain [ + .01abc . + . . + ] +] + ## helpers for drawing editor borders recipe draw-box [ -- cgit 1.4.1-2-gfad0