2016-11-30 00:07:24 +01:00
|
|
|
/* Worker code, contains Netscript scripts that are actually running */
|
2016-11-30 00:38:50 +01:00
|
|
|
//TODO Need some way to stop scripts. Idea: Put a flag in the environment, we can setActive
|
|
|
|
//this flag from outside. If the evaluate() function sees that flag it rejects the current
|
|
|
|
// Promise. We can catch that rejection and stop the script.
|
2016-11-28 23:02:06 +01:00
|
|
|
|
2016-11-30 23:08:21 +01:00
|
|
|
//TODO Tested For and while and generic call statements. Have not tested if statements
|
|
|
|
|
2016-11-28 23:02:06 +01:00
|
|
|
/* Actual Worker Code */
|
|
|
|
function WorkerScript() {
|
2016-11-30 00:38:50 +01:00
|
|
|
this.name = "";
|
|
|
|
this.running = false;
|
|
|
|
this.serverHostname = null;
|
|
|
|
this.code = "";
|
|
|
|
this.env = new Environment();
|
|
|
|
this.timeout = null;
|
2016-11-28 23:02:06 +01:00
|
|
|
}
|
|
|
|
|
2016-11-30 00:07:24 +01:00
|
|
|
//Array containing all scripts that are running across all servers, to easily run them all
|
2016-11-28 23:02:06 +01:00
|
|
|
var workerScripts = [];
|
|
|
|
|
|
|
|
//Loop through workerScripts and run every script that is not currently running
|
|
|
|
function runScriptsLoop() {
|
|
|
|
for (var i = 0; i < workerScripts.length; i++) {
|
|
|
|
if (workerScripts[i].running == false) {
|
|
|
|
var ast = Parser(Tokenizer(InputStream(workerScripts[i].code)));
|
|
|
|
|
2016-11-28 23:13:13 +01:00
|
|
|
console.log("Starting new script: " + workerScripts[i].name);
|
|
|
|
console.log("AST of new script:");
|
|
|
|
console.log(ast);
|
|
|
|
|
2016-11-28 23:02:06 +01:00
|
|
|
workerScripts[i].running = true;
|
2016-11-30 00:38:50 +01:00
|
|
|
evaluate(ast, workerScripts[i]);
|
2016-11-28 23:02:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(runScriptsLoop, 10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
runScriptsLoop();
|