Browse Source

Add printing of all stacks for debugging

ApisNecros 1 year ago
parent
commit
9d4dbfcef6
1 changed files with 18 additions and 1 deletions
  1. 18 1
      starfish.js

+ 18 - 1
starfish.js

@@ -173,7 +173,9 @@ class CodeBox {
         }
         }
     }
     }
 
 
-    /** Prints the code box to the console */
+    /** 
+     * Prints the code box to the console
+     */
     PrintCodeBox() {
     PrintCodeBox() {
         let output = "";
         let output = "";
         for (let y = 0; y < this.box.length; y++) {
         for (let y = 0; y < this.box.length; y++) {
@@ -190,6 +192,20 @@ class CodeBox {
         console.log(output);
         console.log(output);
     }
     }
 
 
+    /**
+     * Prints all stacks to the console
+     */
+    PrintStacks() {
+        let output = "{\n";
+
+        for (let i = 0; i < this.stacks.length; i++) {
+            output += `\t${i}: ${JSON.stringify(this.stacks[i].stack)},\n`
+        }
+        output += "}";
+
+        console.log(output);
+    }
+
     /**
     /**
      * Make all the rows in the code box the same length
      * Make all the rows in the code box the same length
      *
      *
@@ -458,6 +474,7 @@ class CodeBox {
 
 
     Swim() {
     Swim() {
         if(this.debug.print.codeBox) { this.PrintCodeBox(); }
         if(this.debug.print.codeBox) { this.PrintCodeBox(); }
+        if(this.debug.print.stacks) { this.PrintStacks(); }
 
 
         const instruction = this.box[this.pointer.Y][this.pointer.X];
         const instruction = this.box[this.pointer.Y][this.pointer.X];
         this.datetime = new Date();
         this.datetime = new Date();