about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--060string.mu9
-rw-r--r--edit.mu44
2 files changed, 52 insertions, 1 deletions
diff --git a/060string.mu b/060string.mu
index 4a4f6592..3dbfa374 100644
--- a/060string.mu
+++ b/060string.mu
@@ -111,7 +111,8 @@ recipe new-buffer [
   len:address:number <- get-address result:address:buffer/deref, length:offset
   len:address:number/deref <- copy 0:literal
   s:address:address:array:character <- get-address result:address:buffer/deref, data:offset
-  capacity:number <- next-ingredient
+  capacity:number, found?:boolean <- next-ingredient
+  assert found?:boolean, [new-buffer must get a capacity argument]
   s:address:address:array:character/deref <- new character:type, capacity:number
 #?   $print s:address:address:array:character/deref, [
 #? ]
@@ -173,7 +174,13 @@ recipe buffer-append [
     in:address:buffer <- grow-buffer in:address:buffer
   }
   s:address:array:character <- get in:address:buffer/deref, data:offset
+#?   $print [array underlying buf: ], s:address:array:character, [ 
+#? ] #? 1
+#?   $print [index: ], len:address:number/deref, [ 
+#? ] #? 1
   dest:address:character <- index-address s:address:array:character/deref, len:address:number/deref
+#?   $print [storing ], c:character, [ in ], dest:address:character, [ 
+#? ] #? 1
   dest:address:character/deref <- copy c:character
   len:address:number/deref <- add len:address:number/deref, 1:literal
   reply in:address:buffer/same-as-ingredient:0
diff --git a/edit.mu b/edit.mu
index 245762b0..18ae0951 100644
--- a/edit.mu
+++ b/edit.mu
@@ -1734,6 +1734,50 @@ recipe reset-focus [
   }
 ]
 
+## Running code from the editors
+
+recipe editor-contents [
+  default-space:address:array:location <- new location:type, 30:literal
+  editor:address:editor-data <- next-ingredient
+  buf:address:buffer <- new-buffer 80:literal
+#?   $print [buffer: ], buf:address:buffer, [ 
+#? ] #? 1
+  curr:address:duplex-list <- get editor:address:editor-data/deref, data:offset
+  # skip § sentinel
+  assert curr:address:duplex-list, [editor without data is illegal; must have at least a sentinel]
+  curr:address:duplex-list <- next-duplex curr:address:duplex-list
+  {
+    break-unless curr:address:duplex-list
+    c:character <- get curr:address:duplex-list/deref, value:offset
+#?     $print [appending ], c:character, [ 
+#? ] #? 1
+    buffer-append buf:address:buffer, c:character
+    curr:address:duplex-list <- next-duplex curr:address:duplex-list
+    loop
+  }
+  result:address:array:character <- buffer-to-array buf:address:buffer
+  reply result:address:array:character
+]
+
+scenario editor-provides-edited-contents [
+  assume-screen 10:literal/width, 5:literal/height
+  1:address:array:character <- new [abc]
+  2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 10:literal/right
+  assume-console [
+    left-click 0, 2
+    type [def]
+  ]
+  run [
+    event-loop screen:address, console:address, 2:address:editor-data
+    3:address:array:character <- editor-contents 2:address:editor-data
+    4:array:character <- copy 3:address:array:character/deref
+#?     $dump-memory #? 1
+  ]
+  memory-should-contain [
+    4:string <- [abdefc]
+  ]
+]
+
 ## helpers for drawing editor borders
 
 recipe draw-box [