about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-26 15:16:36 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-26 15:16:36 -0700
commitc8a58cdc8cc3353de3a42a9f53e5c4759ef9701a (patch)
tree367f52a1cc671b73696abf3f905632b195f95e1a
parent5b84f01fdcf30ffb62d53ed6f5886f626d47bcfa (diff)
downloadmu-c8a58cdc8cc3353de3a42a9f53e5c4759ef9701a.tar.gz
1473
-rw-r--r--032array.cc28
-rw-r--r--033length.cc27
-rw-r--r--html/032array.cc.html33
-rw-r--r--index.html2
4 files changed, 60 insertions, 30 deletions
diff --git a/032array.cc b/032array.cc
index deef886e..0d8efc5c 100644
--- a/032array.cc
+++ b/032array.cc
@@ -139,3 +139,31 @@ case INDEX_ADDRESS: {
   products.at(0).push_back(result);
   break;
 }
+
+//:: compute the length of an array
+
+:(scenario array_length)
+recipe main [
+  1:number <- copy 3:literal  # length
+  2:number <- copy 14:literal
+  3:number <- copy 15:literal
+  4:number <- copy 16:literal
+  5:number <- length 1:array:number
+]
++mem: storing 3 in location 5
+
+:(before "End Primitive Recipe Declarations")
+LENGTH,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["length"] = LENGTH;
+:(before "End Primitive Recipe Implementations")
+case LENGTH: {
+  reagent x = canonize(current_instruction().ingredients.at(0));
+  if (x.types.at(0) != Type_number["array"]) {
+    raise << "tried to calculate length of non-array " << x.to_string() << '\n';
+    break;
+  }
+  products.resize(1);
+  products.at(0).push_back(Memory[x.value]);
+  break;
+}
diff --git a/033length.cc b/033length.cc
deleted file mode 100644
index 66665631..00000000
--- a/033length.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-//: Recipe to compute the length of an array.
-
-:(scenario array_length)
-recipe main [
-  1:number <- copy 3:literal  # length
-  2:number <- copy 14:literal
-  3:number <- copy 15:literal
-  4:number <- copy 16:literal
-  5:number <- length 1:array:number
-]
-+mem: storing 3 in location 5
-
-:(before "End Primitive Recipe Declarations")
-LENGTH,
-:(before "End Primitive Recipe Numbers")
-Recipe_number["length"] = LENGTH;
-:(before "End Primitive Recipe Implementations")
-case LENGTH: {
-  reagent x = canonize(current_instruction().ingredients.at(0));
-  if (x.types.at(0) != Type_number["array"]) {
-    raise << "tried to calculate length of non-array " << x.to_string() << '\n';
-    break;
-  }
-  products.resize(1);
-  products.at(0).push_back(Memory[x.value]);
-  break;
-}
diff --git a/html/032array.cc.html b/html/032array.cc.html
index 7bb0495f..cac483a1 100644
--- a/html/032array.cc.html
+++ b/html/032array.cc.html
@@ -10,9 +10,10 @@
 <meta name="colorscheme" content="minimal">
 <style type="text/css">
 <!--
-pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; }
-body { font-family: monospace; color: #d0d0d0; background-color: #000000; }
+pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #080808; }
+body { font-family: monospace; color: #d0d0d0; background-color: #080808; }
 * { font-size: 1em; }
+.cSpecial { color: #008000; }
 .CommentedCode { color: #6c6c6c; }
 .Constant { color: #008080; }
 .Comment { color: #8080ff; }
@@ -173,6 +174,34 @@ case INDEX_ADDRESS: <span class="Delimiter">{</span>
   products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span>
   <span class="Identifier">break</span><span class="Delimiter">;</span>
 <span class="Delimiter">}</span>
+
+<span class="SalientComment">//:: compute the length of an array</span>
+
+<span class="Delimiter">:(scenario array_length)</span>
+recipe main [
+  <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">3</span>:literal  <span class="Comment"># length</span>
+  <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">14</span>:literal
+  <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">15</span>:literal
+  <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">16</span>:literal
+  <span class="Constant">5</span>:number<span class="Special"> &lt;- </span>length <span class="Constant">1</span>:array:number
+]
+<span class="traceContains">+mem: storing 3 in location 5</span>
+
+<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
+LENGTH<span class="Delimiter">,</span>
+<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
+Recipe_number[<span class="Constant">&quot;length&quot;</span>] = LENGTH<span class="Delimiter">;</span>
+<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
+case LENGTH: <span class="Delimiter">{</span>
+  reagent x = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
+  if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != Type_number[<span class="Constant">&quot;array&quot;</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span>
+    raise &lt;&lt; <span class="Constant">&quot;tried to calculate length of non-array &quot;</span> &lt;&lt; x<span class="Delimiter">.</span>to_string<span class="Delimiter">()</span> &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
+    <span class="Identifier">break</span><span class="Delimiter">;</span>
+  <span class="Delimiter">}</span>
+  products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span>
+  products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>Memory[x<span class="Delimiter">.</span>value]<span class="Delimiter">);</span>
+  <span class="Identifier">break</span><span class="Delimiter">;</span>
+<span class="Delimiter">}</span>
 </pre>
 </body>
 </html>
diff --git a/index.html b/index.html
index 977cfafd..0d00cc27 100644
--- a/index.html
+++ b/index.html
@@ -88,7 +88,7 @@ akin to records, structs or classes.
 <br/><a href='html/031address.cc.html'>031address.cc</a>: adding and removing
 layers of indirection to mu data.
 <br/><a href='html/032array.cc.html'>032array.cc</a>: all mu data structures
-are <a href='html/033length.cc.html'>bounds-checked</a>.
+are bounds-checked.
 <br/><a href='html/034exclusive_container.cc.html'>034exclusive_container.cc</a>: tagged unions or sum types.
 <br/><a href='html/035call.cc.html'>035call.cc</a>: calls to recipes look
 just like primitive operations.