|
@@ -2,7 +2,7 @@
|
|
* The code box class
|
|
* The code box class
|
|
*/
|
|
*/
|
|
class CodeBox {
|
|
class CodeBox {
|
|
- constructor() {
|
|
|
|
|
|
+ constructor(codeBoxID, initialStackID, outputID) {
|
|
/**
|
|
/**
|
|
* Possible vectors the pointer can move in
|
|
* Possible vectors the pointer can move in
|
|
* @type {Object}
|
|
* @type {Object}
|
|
@@ -59,6 +59,21 @@ class CodeBox {
|
|
* @type {Stack}
|
|
* @type {Stack}
|
|
*/
|
|
*/
|
|
this.stack = new Stack();
|
|
this.stack = new Stack();
|
|
|
|
+
|
|
|
|
+ this.codeBoxDOM = document.getElementById(codeBoxID);
|
|
|
|
+ if(!this.codeBoxDOM) {
|
|
|
|
+ throw new Error(`Failed to find textarea with ID: ${codeBoxID}`);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.outputDOM = document.getElementById(outputID);
|
|
|
|
+ if(!this.outputDOM) {
|
|
|
|
+ throw new Error(`Failed to find textarea with ID: ${outputID}`);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.initialStackDOM = document.getElementById(initialStackID);
|
|
|
|
+ if(!this.initialStackDOM) {
|
|
|
|
+ throw new Error(`Failed to find input with ID: ${initialStackID}`);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -68,7 +83,7 @@ class CodeBox {
|
|
* @param {*} value
|
|
* @param {*} value
|
|
*/
|
|
*/
|
|
Output(value) {
|
|
Output(value) {
|
|
- console.log(value);
|
|
|
|
|
|
+ this.outputDOM.value += value;
|
|
}
|
|
}
|
|
|
|
|
|
Execute(instruction) {
|
|
Execute(instruction) {
|