Browse Source

Add a name value to each computer

Each computer now gets a UUID for a name upon creation. This is mostly
for debugging, and is not intended to be human-readable.
ApisNecros 1 year ago
parent
commit
b60d6e320e
1 changed files with 3 additions and 1 deletions
  1. 3 1
      IntComp/Computer.js

+ 3 - 1
IntComp/Computer.js

@@ -1,5 +1,6 @@
 const prompt = require("prompt-sync")({ sigint: true });
 const util = require("util");
+const uuid = require("uuid");
 
 const Stack = require("./Stack");
 const ComputerParameterMode = require("./ComputerParameterMode");
@@ -24,6 +25,7 @@ module.exports = class Computer {
      * @param {number[]} options.inputModeMap Map calls to the INPUT opcode to user input or the input array
      */
     constructor(stack, options = {}) {
+        this.name = uuid.v4();
         this._initialMemory = DeepClone(stack);
         this.stack = new Stack(stack);
         this.OPCODES = {
@@ -471,7 +473,7 @@ module.exports = class Computer {
             toInspect = this[propertyName];
         }
 
-        console.log(outputMessage, util.inspect(toInspect, { breakLength: Infinity, colors: true, compact: true }));
+        console.log(this.name, outputMessage, util.inspect(toInspect, { breakLength: Infinity, colors: true, compact: true }));
     }
 
     /**