Fix BST to actually work :-)
authorAlyssa Rosenzweig <alyssa@backtick.town>
Thu, 23 Jun 2016 16:09:52 +0000 (09:09 -0700)
committerAlyssa Rosenzweig <alyssa@backtick.town>
Thu, 23 Jun 2016 16:09:52 +0000 (09:09 -0700)
src/CPU/build-cpu.js

index 58dac1d..61c3d1a 100644 (file)
@@ -28,10 +28,9 @@ var sources = table.map(function(x, i) {
 });
 
 // dump out an 8 level deep BST
-console.log(bst(sources, 0, 7));
+console.log(bst(sources, 0, 255).join('\n'));
 
 function bst(sources, start, end) {
-    console.log(start + " - " + end);
     if(start == end)
         return [sources[start]];
 
@@ -40,16 +39,15 @@ function bst(sources, start, end) {
             "if tmp = " + start + " then",
                 sources[start],
             "else",
-                sources[end]
+                sources[end],
+            "end"
             ];
 
-    var emission = [
-        "if tmp < " + (start+end+1)/2 + " then",
-            bst(sources, start, start + (end-start-1) / 2),
-        "else",
-            bst(sources, start + (end-start+1) / 2, end),
-        "end"
-    ];
+    var emission = ["if tmp < " + (start+end+1)/2 + " then"]
+        .concat(bst(sources, start, start + (end-start-1) / 2))
+        .concat(["else"])
+        .concat(bst(sources, start + (end-start+1) / 2, end))
+        .concat(["end"]);
 
     return emission;
 }
This page took 0.02361 seconds and 4 git commands to generate.