Implemented the stack register, and added two example to test it. The second example demonstrates its persistence between stacks.
@@ -19,4 +19,8 @@ abcdef0983[D3[DIID]I]; prints nothing, and ends with the stack in the same orde
c22g\ prints "5011012", or what should be read as "50", "110", and "12"
/g32/
\nnn;
- 2
+ 2
+
+f:&&1+nn; prints "1615"
+abcdefr&r3[D&n; prints "10"
@@ -290,6 +290,15 @@ class CodeBox {
if(this.stacks[this.curr_stack].Pop() === 0){ this.Move(); }
break;
// Stack manipulation
+ case "&": {
+ if (this.stacks[this.curr_stack].register == null) {
+ this.stacks[this.curr_stack].register = this.stacks[this.curr_stack].Pop();
+ }
+ else {
+ this.stacks[this.curr_stack].Push(this.stacks[this.curr_stack].register);
+ this.stacks[this.curr_stack].register = null;
case ":":
this.stacks[this.curr_stack].Duplicate();
@@ -351,7 +360,7 @@ class CodeBox {
output = true;
default:
- throw new Error();
+ throw new Error(`Unknown instruction: ${instruction}`);
}
catch(e) {