|
@@ -280,9 +280,9 @@ class CodeBox {
|
|
|
case "$":
|
|
|
this.stack.SwapTwo();
|
|
|
break;
|
|
|
- // case "@":
|
|
|
- // this.stack.SwapThree();
|
|
|
- // break;
|
|
|
+ case "@":
|
|
|
+ this.stack.SwapThree();
|
|
|
+ break;
|
|
|
case "{":
|
|
|
this.stack.ShiftLeft();
|
|
|
break;
|
|
@@ -577,7 +577,22 @@ class Stack {
|
|
|
* Swaps the top two values of the stack
|
|
|
*/
|
|
|
SwapTwo() {
|
|
|
- // TODO
|
|
|
+ if(this.stack.length < 2) { throw new Error("Something's Fishy"); }
|
|
|
+ const popped = this.stack.splice(this.stack.length - 2, 2);
|
|
|
+ this.stack.push(...popped.reverse());
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Implement @
|
|
|
+ *
|
|
|
+ * Swaps the top three values of the stack
|
|
|
+ */
|
|
|
+ SwapThree() {
|
|
|
+ if(this.stack.length < 3) { throw new Error("Something's Fishy"); }
|
|
|
+ // Get the top three values
|
|
|
+ const popped = this.stack.splice(this.stack.length - 3, 3);
|
|
|
+ // Shift the elements to the right
|
|
|
+ popped.unshift(popped.pop());
|
|
|
+ this.stack.push(...popped);
|
|
|
}
|
|
|
|
|
|
/**
|