Jelajahi Sumber

Implement C and R

Implemented the Call and Ret instructions.
ApisNecros 1 tahun lalu
induk
melakukan
4130af3910
1 mengubah file dengan 15 tambahan dan 0 penghapusan
  1. 15 0
      starfish.js

+ 15 - 0
starfish.js

@@ -463,6 +463,21 @@ class CodeBox {
                     this.pointer.X = this.stacks[this.curr_stack].Pop();
                     break;
                 }
+                case "C": {
+                    const currCoords = new Stack([this.pointer.X, this.pointer.Y]);
+                    this.stacks.splice(this.curr_stack, 0, currCoords);
+                    this.curr_stack++;
+                    this.pointer.Y = this.stacks[this.curr_stack].Pop();
+                    this.pointer.X = this.stacks[this.curr_stack].Pop();
+                    break;
+                }
+                case "R": {
+                    const newCoords = this.stacks.splice(this.curr_stack - 1, 1).pop();
+                    this.curr_stack--;
+                    this.pointer.Y = newCoords.Pop()
+                    this.pointer.X = newCoords.Pop();
+                    break;
+                }
                 // End execution
                 case ";":
                     output = true;