about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-20 22:55:01 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-20 22:59:27 -0700
commit70179d1f132ab3170d9fda9b002f4d82af5b0a56 (patch)
treeccb15976c3678b7464108cf32000df97d5bee90c
parent9897c8177bba26946a54513f5a8113a375f205f0 (diff)
downloadmu-70179d1f132ab3170d9fda9b002f4d82af5b0a56.tar.gz
1611 - switch to keyboard+mouse events
-rw-r--r--020run.cc14
-rw-r--r--032array.cc4
-rw-r--r--077mouse.cc6
-rw-r--r--078mouse.mu8
-rw-r--r--edit.mu20
5 files changed, 42 insertions, 10 deletions
diff --git a/020run.cc b/020run.cc
index 90413df3..9e6cbb2c 100644
--- a/020run.cc
+++ b/020run.cc
@@ -194,8 +194,10 @@ vector<double> read_memory(reagent x) {
 void write_memory(reagent x, vector<double> data) {
   if (is_dummy(x)) return;
   long long int base = x.value;
-  if (size_of(x) != SIZE(data))
-    raise << "size mismatch in storing to " << x.to_string() << '\n';
+  if (size_mismatch(x, data)) {
+    tb_shutdown();
+    raise << current_recipe_name() << ": size mismatch in storing to " << x.to_string() << " at " << current_instruction().to_string() << '\n' << die();
+  }
   for (long long int offset = 0; offset < SIZE(data); ++offset) {
     trace(Primitive_recipe_depth, "mem") << "storing " << data.at(offset) << " in location " << base+offset;
     Memory[base+offset] = data.at(offset);
@@ -211,6 +213,14 @@ long long int size_of(const vector<type_number>& types) {
   return 1;
 }
 
+bool size_mismatch(const reagent& x, const vector<double>& data) {
+  if (size_of(x) != SIZE(data)) {
+    tb_shutdown();
+    cerr << size_of(x) << " vs " << SIZE(data) << '\n';
+  }
+  return size_of(x) != SIZE(data);
+}
+
 bool is_dummy(const reagent& x) {
   return x.name == "_";
 }
diff --git a/032array.cc b/032array.cc
index 87a97291..1ca54ef0 100644
--- a/032array.cc
+++ b/032array.cc
@@ -38,8 +38,8 @@ recipe main [
 +mem: storing 16 in location 9
 
 //: disable the size mismatch check since the destination array need not be initialized
-:(replace "if (size_of(x) != SIZE(data))" following "void write_memory(reagent x, vector<double> data)")
-if (x.types.at(0) != Type_number["array"] && size_of(x) != SIZE(data))
+:(after "bool size_mismatch(const reagent& x, const vector<double>& data)")
+if (x.types.at(0) == Type_number["array"]) return false;
 :(after "long long int size_of(const reagent& r)")
   if (r.types.at(0) == Type_number["array"]) {
     assert(SIZE(r.types) > 1);
diff --git a/077mouse.cc b/077mouse.cc
index e458574a..124e8db2 100644
--- a/077mouse.cc
+++ b/077mouse.cc
@@ -14,6 +14,8 @@ case READ_KEYBOARD_OR_MOUSE_EVENT: {
     if (key == TB_KEY_BACKSPACE2) key = TB_KEY_BACKSPACE;
     if (key == TB_KEY_CARRIAGE_RETURN) key = TB_KEY_NEWLINE;
     products.at(0).push_back(key);
+    products.at(0).push_back(0);
+    products.at(0).push_back(0);
     products.at(1).push_back(/*found*/true);
     break;
   }
@@ -28,6 +30,10 @@ case READ_KEYBOARD_OR_MOUSE_EVENT: {
     products.at(1).push_back(/*found*/true);
     break;
   }
+  products.at(0).push_back(0);
+  products.at(0).push_back(0);
+  products.at(0).push_back(0);
+  products.at(0).push_back(0);
   products.at(1).push_back(/*found*/false);
   break;
 }
diff --git a/078mouse.mu b/078mouse.mu
index 2590131f..614b986f 100644
--- a/078mouse.mu
+++ b/078mouse.mu
@@ -31,13 +31,13 @@ recipe read-event [
       done?:boolean <- greater-or-equal idx:address:number/deref, max:number
       break-unless done?:boolean
       dummy:address:event <- new event:type
-      reply dummy:address:event/deref, x:address:events/same-as-ingredient:0
+      reply dummy:address:event/deref, x:address:events/same-as-ingredient:0, 1:literal/found
     }
     result:event <- index buf:address:array:event/deref, idx:address:number/deref
     idx:address:number/deref <- add idx:address:number/deref, 1:literal
-    reply result:event, x:address:events/same-as-ingredient:0
+    reply result:event, x:address:events/same-as-ingredient:0, 1:literal/found
   }
   # real event source
-  result:event <- read-keyboard-or-mouse-event
-  reply result:event
+  result:event, found?:boolean <- read-keyboard-or-mouse-event
+  reply result:event, x:address:events/same-as-ingredient:0, found?:boolean
 ]
diff --git a/edit.mu b/edit.mu
index 71fdaaa9..dec89e88 100644
--- a/edit.mu
+++ b/edit.mu
@@ -13,7 +13,7 @@ ghi
 jkl
 ]
   editor:address:editor-data <- new-editor in:address:array:character, 0:literal/screen, 0:literal/top, 0:literal/left, divider:number/right
-  wait-for-key-from-keyboard
+  event-loop 0:literal/screen, 0:literal/events, editor:address:editor-data
   return-to-console
 ]
 
@@ -29,6 +29,9 @@ scenario editor-initially-prints-string-to-screen [
   ]
 ]
 
+## In which we introduce the editor data structure, and show how it displays
+## text to the screen.
+
 container editor-data [
   # doubly linked list of characters
   data:address:duplex-list
@@ -265,7 +268,20 @@ scenario editor-initially-wraps-long-lines [
   ]
 ]
 
-## some drawing primitives
+## handling events from the keyboard and mouse
+
+recipe event-loop [
+  default-space:address:array:location <- new location:type, 30:literal
+  screen:address <- next-ingredient
+  events:address <- next-ingredient
+  editor:address:editor-data <- next-ingredient
+  {
+    _, _, found?:boolean <- read-event 0:literal/events
+    loop-unless found?:boolean
+  }
+]
+
+## helpers for drawing editor borders
 
 recipe draw-box [
   default-space:address:array:location <- new location:type, 30:literal