|
@@ -152,8 +152,10 @@ class CodeBox {
|
|
Execute(instruction) {
|
|
Execute(instruction) {
|
|
let output = null;
|
|
let output = null;
|
|
switch(instruction) {
|
|
switch(instruction) {
|
|
|
|
+ // NOP
|
|
case " ":
|
|
case " ":
|
|
break;
|
|
break;
|
|
|
|
+ // Numbers
|
|
case "1":
|
|
case "1":
|
|
case "2":
|
|
case "2":
|
|
case "3":
|
|
case "3":
|
|
@@ -172,6 +174,7 @@ class CodeBox {
|
|
case "f":
|
|
case "f":
|
|
this.stack.Push(parseInt(instruction, 16));
|
|
this.stack.Push(parseInt(instruction, 16));
|
|
break;
|
|
break;
|
|
|
|
+ // Operators
|
|
case "+": {
|
|
case "+": {
|
|
const x = this.stack.Pop();
|
|
const x = this.stack.Pop();
|
|
const y = this.stack.Pop();
|
|
const y = this.stack.Pop();
|
|
@@ -202,12 +205,14 @@ class CodeBox {
|
|
this.stack.Push(y % x);
|
|
this.stack.Push(y % x);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+ // Output
|
|
case "n":
|
|
case "n":
|
|
output = this.stack.Pop();
|
|
output = this.stack.Pop();
|
|
break;
|
|
break;
|
|
case "o":
|
|
case "o":
|
|
output = String.fromCharCode(this.stack.Pop());
|
|
output = String.fromCharCode(this.stack.Pop());
|
|
break;
|
|
break;
|
|
|
|
+ // End execution
|
|
case ";":
|
|
case ";":
|
|
output = true;
|
|
output = true;
|
|
break;
|
|
break;
|