Pārlūkot izejas kodu

Implement p

Added the p instruction which allows for adding instruction to the code
box at aspecified positions.
ApisNecros 1 gadu atpakaļ
vecāks
revīzija
81ab8f4b7e
1 mainītis faili ar 26 papildinājumiem un 1 dzēšanām
  1. 26 1
      starfish.js

+ 26 - 1
starfish.js

@@ -351,10 +351,13 @@ class CodeBox {
                 case "o":
                     output = String.fromCharCode(this.stacks[this.curr_stack].Pop());
                     break;
-                // Misc
+                // Code box manipulation
                 case "g":
                     this.PushFromCodeBox();
                     break;
+                case "p":
+                    this.PlaceIntoCodeBox();
+                    break;
                 // End execution
                 case ";":
                     output = true;
@@ -624,6 +627,28 @@ class CodeBox {
 
         this.stacks[this.curr_stack].Push(valParsed);
     }
+    /**
+     * Implement p
+     * 
+     * Pops `y`, `x`, and `v` off of the stack, and then places the string
+     * representation of that value at `[x, y]` in the code box.
+     */
+    PlaceIntoCodeBox() {
+        const y = this.stacks[this.curr_stack].Pop();
+        const x = this.stacks[this.curr_stack].Pop();
+        const v = this.stacks[this.curr_stack].Pop();
+
+        while(y >= this.box.length) {
+            this.box.push([]);
+        }
+        while(x >= this.box[y].length) {
+            this.box[y].push(" ");
+        }
+
+        this.EqualizeBoxWidth();
+
+        this.box[y][x] = String.fromCharCode(v);
+    }
 
     /**
      * Implement `