about summary refs log tree commit diff stats
path: root/edit
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-06-15 22:12:03 -0700
committerKartik Agaram <vc@akkartik.com>2018-06-15 22:12:03 -0700
commit0edd9b9fc60440213e4df926ea511419ee291f1e (patch)
tree84b22f7afdeb9110ad7105c5fc070dacff178502 /edit
parent3f34ac9369978b396d00a4fd02c9fb06b8eea621 (diff)
downloadmu-0edd9b9fc60440213e4df926ea511419ee291f1e.tar.gz
4257 - abortive attempt at safe fat pointers
I've been working on this slowly over several weeks, but it's too hard
to support 0 as the null value for addresses. I constantly have to add
exceptions for scalar value corresponding to an address type (now
occupying 2 locations). The final straw is the test for 'reload':

  x:num <- reload text

'reload' returns an address. But there's no way to know that for
arbitrary instructions.

New plan: let's put this off for a bit and first create support for
literals. Then use 'null' instead of '0' for addresses everywhere. Then
it'll be easy to just change what 'null' means.
Diffstat (limited to 'edit')
-rw-r--r--edit/001-editor.mu22
-rw-r--r--edit/002-typing.mu4
-rw-r--r--edit/003-shortcuts.mu23
3 files changed, 39 insertions, 10 deletions
diff --git a/edit/001-editor.mu b/edit/001-editor.mu
index 8855395a..036ef07a 100644
--- a/edit/001-editor.mu
+++ b/edit/001-editor.mu
@@ -81,18 +81,20 @@ scenario editor-initializes-without-data [
   assume-screen 5/width, 3/height
   run [
     e:&:editor <- new-editor 0/data, 2/left, 5/right
-    2:editor/raw <- copy *e
+    1:editor/raw <- copy *e
   ]
   memory-should-contain [
-    # 2 (data) <- just the § sentinel
-    # 3 (top of screen) <- the § sentinel
-    4 <- 0  # bottom-of-screen; null since text fits on screen
-    # 5 (before cursor) <- the § sentinel
-    6 <- 2  # left
-    7 <- 4  # right  (inclusive)
-    8 <- 0  # bottom (not set until render)
-    9 <- 1  # cursor row
-    10 <- 2  # cursor column
+    # 1,2 (data) <- just the § sentinel
+    # 3,4 (top of screen) <- the § sentinel
+    # 5 (bottom of screen) <- null since text fits on screen
+    5 <- 0
+    6 <- 0
+    # 7,8 (before cursor) <- the § sentinel
+    9 <- 2  # left
+    10 <- 4  # right  (inclusive)
+    11 <- 0  # bottom (not set until render)
+    12 <- 1  # cursor row
+    13 <- 2  # cursor column
   ]
   screen-should-contain [
     .     .
diff --git a/edit/002-typing.mu b/edit/002-typing.mu
index 47885c4f..67fe76a0 100644
--- a/edit/002-typing.mu
+++ b/edit/002-typing.mu
@@ -280,7 +280,11 @@ scenario editor-handles-empty-event-queue [
   assume-screen 10/width, 5/height
   e:&:editor <- new-editor [abc], 0/left, 10/right
   editor-render screen, e
+#?   x:num <- get *screen, num-rows:offset
+#?   $print [a: ] x 10/newline
   assume-console []
+#?   x:num <- get *screen, num-rows:offset
+#?   $print [z: ] x 10/newline
   run [
     editor-event-loop screen, console, e
   ]
diff --git a/edit/003-shortcuts.mu b/edit/003-shortcuts.mu
index 02ea77d0..78c6e49f 100644
--- a/edit/003-shortcuts.mu
+++ b/edit/003-shortcuts.mu
@@ -2006,7 +2006,13 @@ after <handle-special-character> [
     delete-to-start-of-line?:bool <- equal c, 21/ctrl-u
     break-unless delete-to-start-of-line?
     <begin-delete-to-start-of-line>
+    $print [before: ] cursor-row [ ] cursor-column 10/newline
     deleted-cells:&:duplex-list:char <- delete-to-start-of-line editor
+    x:text <- to-text deleted-cells
+    $print x 10/newline
+    cursor-row <- get *editor, cursor-row:offset
+    cursor-column <- get *editor, cursor-column:offset
+    $print [after: ] cursor-row [ ] cursor-column 10/newline
     <end-delete-to-start-of-line>
     go-render?:bool <- minimal-render-for-ctrl-u screen, editor, deleted-cells
     return
@@ -2016,6 +2022,7 @@ after <handle-special-character> [
 def minimal-render-for-ctrl-u screen:&:screen, editor:&:editor, deleted-cells:&:duplex-list:char -> go-render?:bool, screen:&:screen [
   local-scope
   load-inputs
+  $print [minimal render for ctrl-u] 10/newline
   curr-column:num <- get *editor, cursor-column:offset
   # accumulate the current line as text and render it
   buf:&:buffer:char <- new-buffer 30  # accumulator for the text we need to render
@@ -2025,6 +2032,7 @@ def minimal-render-for-ctrl-u screen:&:screen, editor:&:editor, deleted-cells:&:
   {
     # if we have a wrapped line, give up and render the whole screen
     wrap?:bool <- greater-or-equal i, right
+    $print [wrap? ] wrap? 10/newline
     return-if wrap?, 1/go-render
     curr <- next curr
     break-unless curr
@@ -2061,6 +2069,7 @@ def delete-to-start-of-line editor:&:editor -> result:&:duplex-list:char, editor
   {
     at-start-of-text?:bool <- equal start, init
     break-if at-start-of-text?
+    $print [0] 10/newline
     curr:char <- get *start, value:offset
     at-start-of-line?:bool <- equal curr, 10/newline
     break-if at-start-of-line?
@@ -2071,14 +2080,23 @@ def delete-to-start-of-line editor:&:editor -> result:&:duplex-list:char, editor
     assert start, [delete-to-start-of-line tried to move before start of text]
     loop
   }
+  $print [1] 10/newline
   # snip it out
   result:&:duplex-list:char <- next start
+  x:text <- to-text start
+  $print [start: ] x 10/newline
+  x:text <- to-text end
+  $print [end: ] x 10/newline
   remove-between start, end
+  x:text <- to-text result
+  $print [snip: ] x 10/newline
   # update top-of-screen if it's just been invalidated
   {
     break-unless update-top-of-screen?
+    $print [2] 10/newline
     put *editor, top-of-screen:offset, start
   }
+  $print [3] 10/newline
   # adjust cursor
   before-cursor <- copy start
   *editor <- put *editor, before-cursor:offset, before-cursor
@@ -2089,17 +2107,22 @@ def delete-to-start-of-line editor:&:editor -> result:&:duplex-list:char, editor
   width:num <- subtract right, left
   num-deleted:num <- length result
   cursor-row-adjustment:num <- divide-with-remainder num-deleted, width
+  $print [adj ] num-deleted [/] width [=] cursor-row-adjustment 10/newline
   return-unless cursor-row-adjustment
+  $print [4] 10/newline
   cursor-row:num <- get *editor, cursor-row:offset
   cursor-row-in-editor:num <- subtract cursor-row, 1  # ignore menubar
   at-top?:bool <- lesser-or-equal cursor-row-in-editor, cursor-row-adjustment
   {
     break-unless at-top?
+    $print [5] 10/newline
     cursor-row <- copy 1  # top of editor, below menubar
   }
   {
     break-if at-top?
+    $print [6] 10/newline
     cursor-row <- subtract cursor-row, cursor-row-adjustment
+    $print cursor-row 10/newline
   }
   put *editor, cursor-row:offset, cursor-row
 ]