From 672e3e50c6ed6de161e40aa256c3fc0f2b1f7cf9 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 6 May 2015 00:19:03 -0700 Subject: 1279 - colorized rendering of the source files --- html/062array.mu.html | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 html/062array.mu.html (limited to 'html/062array.mu.html') diff --git a/html/062array.mu.html b/html/062array.mu.html new file mode 100644 index 00000000..e765ca2a --- /dev/null +++ b/html/062array.mu.html @@ -0,0 +1,74 @@ + + + + +~/Desktop/s/mu/062array.mu.html + + + + + + + + + + +
+scenario array-from-args [
+  run [
+    1:address:array:location <- init-array 0:literal, 1:literal, 2:literal
+    2:array:location <- copy 1:address:array:location/deref
+  ]
+  memory-should-contain [
+    2 <- 3  # array length
+    3 <- 0
+    4 <- 1
+    5 <- 2
+  ]
+]
+
+# create an array out of a list of scalar args
+recipe init-array [
+  default-space:address:array:location <- new location:type, 30:literal
+  capacity:integer <- copy 0:literal
+  {
+    # while read curr-value
+    curr-value:location, exists?:boolean <- next-ingredient
+    break-unless exists?:boolean
+    capacity:integer <- add capacity:integer, 1:literal
+    loop
+  }
+  result:address:array:location <- new location:type, capacity:integer
+  rewind-ingredients
+  i:integer <- copy 0:literal
+  {
+    # while read curr-value
+    done?:boolean <- greater-or-equal i:integer, capacity:integer
+    break-if done?:boolean
+    curr-value:location, exists?:boolean <- next-ingredient
+    assert exists?:boolean, [error in rewinding ingredients to init-array]
+    tmp:address:location <- index-address result:address:array:location/deref, i:integer
+    tmp:address:location/deref <- copy curr-value:location
+    i:integer <- add i:integer, 1:literal
+    loop
+  }
+  reply result:address:array:location
+]
+
+ + + -- cgit 1.4.1-2-gfad0