about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-24 17:43:45 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-24 17:43:45 -0700
commit6179649e43d08e08460382df6a333cdd58ca0a9a (patch)
tree394b50f8306e5c411e52724187b3c60788c75a93
parente766fd13d6d2102491979c98803f566b04d2f258 (diff)
downloadmu-6179649e43d08e08460382df6a333cdd58ca0a9a.tar.gz
1641
Snapshot in switching editor-data.cursor to editor-data.before-cursor.
But I have trouble coercing events to touch events, even though using
the integer tag 2 for the conversion works.
-rw-r--r--002test.cc2
-rw-r--r--041name.cc24
-rw-r--r--043space.cc3
-rw-r--r--070display.cc2
-rw-r--r--edit.mu26
5 files changed, 33 insertions, 24 deletions
diff --git a/002test.cc b/002test.cc
index a35f95bf..d59309a2 100644
--- a/002test.cc
+++ b/002test.cc
@@ -54,7 +54,7 @@ if (Run_tests) {
   time_t t; time(&t);
   cerr << "C tests: " << ctime(&t);
   for (size_t i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) {
-//?     cerr << i << '\n'; //? 1
+//?     cerr << i << '\n'; //? 2
     run_test(i);
   }
   // End Tests
diff --git a/041name.cc b/041name.cc
index 20668ab5..e2c1d940 100644
--- a/041name.cc
+++ b/041name.cc
@@ -69,6 +69,8 @@ void transform_names(const recipe_number r) {
 void check_metadata(map<string, vector<type_number> >& metadata, const reagent& x, const recipe_number r) {
   if (is_literal(x)) return;
   if (is_raw(x)) return;
+  // if you use raw locations you're probably doing something unsafe
+  if (is_integer(x.name)) return;
   if (metadata.find(x.name) == metadata.end())
     metadata[x.name] = x.types;
   if (metadata[x.name] != x.types)
@@ -224,11 +226,12 @@ if (inst.operation == Recipe_number["get"]
   assert(SIZE(inst.ingredients) >= 2);
 //?   cout << inst.ingredients.at(1).to_string() << '\n'; //? 1
   assert(is_literal(inst.ingredients.at(1)));
-  if (inst.ingredients.at(1).name.find_first_not_of("0123456789") == string::npos) continue;
-  // 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);
-  inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name));
-  trace("name") << "element " << inst.ingredients.at(1).name << " of type " << Type[base_type].name << " is at offset " << inst.ingredients.at(1).value;
+  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);
+    inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name));
+    trace("name") << "element " << inst.ingredients.at(1).name << " of type " << Type[base_type].name << " is at offset " << inst.ingredients.at(1).value;
+  }
 }
 
 //: this test is actually illegal so can't call run
@@ -260,9 +263,10 @@ if (inst.operation == Recipe_number["maybe-convert"]) {
   // at least 2 args, and second arg is offset
   assert(SIZE(inst.ingredients) >= 2);
   assert(is_literal(inst.ingredients.at(1)));
-  if (inst.ingredients.at(1).name.find_first_not_of("0123456789") == string::npos) continue;
-  // since first non-address in base type must be an exclusive container, we don't have to canonize
-  type_number base_type = skip_addresses(inst.ingredients.at(0).types);
-  inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name));
-  trace("name") << "variant " << inst.ingredients.at(1).name << " of type " << Type[base_type].name << " has tag " << inst.ingredients.at(1).value;
+  if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) {
+    // since first non-address in base type must be an exclusive container, we don't have to canonize
+    type_number base_type = skip_addresses(inst.ingredients.at(0).types);
+    inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name));
+    trace("name") << "variant " << inst.ingredients.at(1).name << " of type " << Type[base_type].name << " has tag " << inst.ingredients.at(1).value;
+  }
 }
diff --git a/043space.cc b/043space.cc
index ddff7a4a..52c92f87 100644
--- a/043space.cc
+++ b/043space.cc
@@ -55,7 +55,8 @@ reagent absolutize(reagent x) {
 //?   cout << is_raw(x) << '\n'; //? 1
   if (is_raw(x) || is_dummy(x)) return x;
 //?   cout << "not raw: " << x.to_string() << '\n'; //? 1
-  assert(x.initialized);
+  if (!x.initialized)
+    raise << current_instruction().to_string() << ": reagent not initialized: " << x.to_string() << die();
   reagent r = x;
   r.set_value(address(r.value, space_base(r)));
 //?   cout << "after absolutize: " << r.value << '\n'; //? 1
diff --git a/070display.cc b/070display.cc
index 07656c7d..9cec82ca 100644
--- a/070display.cc
+++ b/070display.cc
@@ -271,6 +271,8 @@ case CHECK_FOR_INTERACTION: {
     break;
   }
   if (event_type == TB_EVENT_MOUSE) {
+//?     tb_shutdown(); //? 1
+//?     cerr << "AAA\n"; //? 1
     products.at(0).push_back(/*touch event*/2);
     products.at(0).push_back(event.key);  // which button, etc.
     products.at(0).push_back(event.y);  // row
diff --git a/edit.mu b/edit.mu
index 214925ea..b04b9645 100644
--- a/edit.mu
+++ b/edit.mu
@@ -33,12 +33,12 @@ scenario editor-initially-prints-string-to-screen [
 ## text to the screen.
 
 container editor-data [
-  # doubly linked list of characters
+  # doubly linked list of characters (head contains a special marker)
   data:address:duplex-list
   # location of top-left of screen inside data (scrolling)
   top-of-screen:address:duplex-list
-  # location of cursor inside data
-  cursor:address:duplex-list
+  # location before cursor inside data
+  before-cursor:address:duplex-list
 
   screen:address:screen
   # raw bounds of display area on screen
@@ -65,6 +65,8 @@ recipe new-editor [
   right:number <- next-ingredient
   right:number <- subtract right:number, 1:literal
   result:address:editor-data <- new editor-data:type
+  d:address:address:duplex-list <- get-address result:address:editor-data/deref, data:offset
+  d:address:address:duplex-list/deref <- push-duplex 167:literal/§, 0:literal/tail
   # initialize screen-related fields
   sc:address:address:screen <- get-address result:address:editor-data/deref, screen:offset
   sc:address:address:screen/deref <- copy screen:address
@@ -90,10 +92,7 @@ recipe new-editor [
   # s is guaranteed to have at least one character, so initialize result's
   # duplex-list
   init:address:address:duplex-list <- get-address result:address:editor-data/deref, top-of-screen:offset
-  init:address:address:duplex-list/deref <- copy 0:literal
-  c:character <- index s:address:array:character/deref, idx:number
-  idx:number <- add idx:number, 1:literal
-  init:address:address:duplex-list/deref <- push c:character, init:address:address:duplex-list/deref
+  init:address:address:duplex-list/deref <- copy d:address:address:duplex-list/deref
   curr:address:duplex-list <- copy init:address:address:duplex-list/deref
   # now we can start appending the rest, character by character
   {
@@ -111,7 +110,7 @@ recipe new-editor [
     loop
   }
   # initialize cursor to top of screen
-  y:address:address:duplex-list <- get-address result:address:editor-data/deref, cursor:offset
+  y:address:address:duplex-list <- get-address result:address:editor-data/deref, before-cursor:offset
   y:address:address:duplex-list/deref <- copy init:address:address:duplex-list/deref
   # perform initial rendering to screen
   bottom:address:number <- get-address result:address:editor-data/deref, bottom:offset
@@ -126,9 +125,9 @@ scenario editor-initializes-without-data [
     2:editor-data <- copy 1:address:editor-data/deref
   ]
   memory-should-contain [
-    2 <- 0  # data
+    # 2 <- just the § marker
     3 <- 0  # pointer into data to top of screen
-    4 <- 0  # pointer into data to cursor
+    # 4 (before cursor) <- the § marker
     # 5 <- screen
     6 <- 1  # top
     7 <- 2  # left
@@ -154,6 +153,7 @@ recipe render [
   right:number <- next-ingredient
   # traversing editor
   curr:address:duplex-list <- get editor:address:editor-data/deref, top-of-screen:offset
+  curr:address:duplex-list <- next-duplex curr:address:duplex-list
   # traversing screen
   row:number <- copy top:number
   column:number <- copy left:number
@@ -277,12 +277,14 @@ recipe event-loop [
     break-if quit?:boolean  # only in tests
     trace [app], [next-event]
     {
-      t:address:touch-event <- maybe-convert e:event, touch:variant
+      t:address:touch-event <- maybe-convert e:event, 2:variant
       break-unless t:address:touch-event
       editor:address:editor-data <- move-cursor-in-editor editor:address:editor-data, t:address:touch-event/deref
       loop +next-event:label
     }
+    $print e:event
     c:address:character <- maybe-convert e:event, text:variant
+    close-console
     assert c:address:character, [event was of unknown type; neither keyboard nor mouse]
     loop
   }
@@ -297,7 +299,7 @@ recipe move-cursor-in-editor [
   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, cursor:offset
+  cursor:address:address:duplex-list <- get-address editor:address:editor-data/deref, before-cursor:offset
   cursor:address:address:duplex-list/deref <- copy 0:literal
 ]