about summary refs log tree commit diff stats
path: root/edit.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-14 21:37:24 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-14 21:37:24 -0700
commit5f60c00a9026eb382c064d76b50cc6ce756514fe (patch)
tree422a53c92489cdf341bc2c81336fbede597b5bfe /edit.mu
parent094548498bfd351d2b2f7323e7757113654dbab1 (diff)
downloadmu-5f60c00a9026eb382c064d76b50cc6ce756514fe.tar.gz
1783 - stable if sluggish on caleb's 512MB server
Profiling shows the bulk of time is spent in read_memory, canonize,
absolutize. But I'm not sure how to optimize those places.
Diffstat (limited to 'edit.mu')
-rw-r--r--edit.mu51
1 files changed, 45 insertions, 6 deletions
diff --git a/edit.mu b/edit.mu
index 518d7ed7..255e63bd 100644
--- a/edit.mu
+++ b/edit.mu
@@ -3,13 +3,52 @@
 recipe main [
   local-scope
   open-console
-  initial-recipe:address:array:character <- new [recipe new-add [
-  x:number <- next-ingredient
-  y:number <- next-ingredient
-  z:number <- add x:number, y:number
-  reply z:number
+  initial-recipe:address:array:character <- new [ 
+# return true if a list of numbers contains the pattern 1, 5, 3
+recipe check [
+  default-space:address:array:location <- new location:type, 30:literal
+  state:number <- copy 0:literal
+  {
+    +next-number
+    curr:number, found?:boolean <- next-ingredient
+    break-unless found?:boolean
+    # if curr is 1, state = 1
+    {
+      state1:boolean <- equal curr:number, 1:literal
+      break-unless state1:boolean
+      state:number <- copy 1:literal
+      loop +next-number:label
+    }
+    # if state is 1 and curr is 5, state = 2
+    {
+      state-is-1?:boolean <- equal state:number, 1:literal
+      break-unless state-is-1?:boolean
+      state2:boolean <- equal curr:number, 5:literal
+      break-unless state2:boolean
+      state:number <- copy 2:literal
+      loop +next-number:label
+    }
+    # if state is 2 and curr is 3, return true
+    {
+      state-is-2?:boolean <- equal state:number, 2:literal
+      break-unless state-is-2?:boolean
+      state3:boolean <- equal curr:number, 3:literal
+      break-unless state3:boolean
+      reply 1:literal/found
+    }
+    # otherwise reset state
+    #state:number <- copy 0:literal
+    loop
+  }
+  reply 0:literal/not-found
 ]]
-  initial-sandbox:address:array:character <- new [new-add 2:literal, 3:literal]
+#?   initial-recipe:address:array:character <- new [recipe new-add [
+#?   x:number <- next-ingredient
+#?   y:number <- next-ingredient
+#?   z:number <- add x:number, y:number
+#?   reply z:number
+#? ]]
+  initial-sandbox:address:array:character <- new []
   env:address:programming-environment-data <- new-programming-environment 0:literal/screen, initial-recipe:address:array:character, initial-sandbox:address:array:character
   render-all 0:literal/address, env:address:programming-environment-data
   event-loop 0:literal/screen, 0:literal/console, env:address:programming-environment-data