Fixed new Netscript1 Interpreter to work for functions returning Arrays/Objets. Untested. Also still needs new Hacknet Node implementation

This commit is contained in:
danielyxie 2018-07-10 23:41:26 -05:00
parent dcd6292ed2
commit 3ffc820519
7 changed files with 7294 additions and 4162 deletions

3794
dist/engine.bundle.js vendored

File diff suppressed because one or more lines are too long

3875
dist/vendor.bundle.js vendored

File diff suppressed because it is too large Load Diff

@ -809,7 +809,7 @@
</span>
</label>
<input type ="range" max="250" min="10" step="1" name="settingsNSExecTimeRangeVal" id="settingsNSExecTimeRangeVal" value="100" />
<input type ="range" max="100" min="10" step="1" name="settingsNSExecTimeRangeVal" id="settingsNSExecTimeRangeVal" value="25" />
<em id="settingsNSExecTimeRangeValLabel" style="font-style: normal;"></em>
</fieldset>

File diff suppressed because one or more lines are too long

@ -3254,6 +3254,17 @@ function NetscriptFunctions(workerScript) {
throw makeRuntimeRejectMsg(workerScript, "stopBladeburnerAction() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
"at the Bladeburner division or because you do not have Source-File 7");
},
getCurrentAction : function() {
if (workerScript.checkingRam) {
return updateStaticRam("getCurrentAction", CONSTANTS.ScriptBladeburnerApiBaseRamCost / 4);
}
updateDynamicRam("getCurrentAction", CONSTANTS.ScriptBladeburnerApiBaseRamCost / 2);
if (Player.bladeburner instanceof Bladeburner && (Player.bitNodeN === 7 || hasBladeburner2079SF)) {
return Player.bladeburner.resetAction();
}
throw makeRuntimeRejectMsg(workerScript, "getCurrentAction() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
"at the Bladeburner division or because you do not have Source-File 7");
},
getActionTime : function(type="", name="") {
if (workerScript.checkingRam) {
return updateStaticRam("getActionTime", CONSTANTS.ScriptBladeburnerApiBaseRamCost);

@ -163,7 +163,7 @@ function startNetscript1Script(workerScript) {
var interpreterInitialization = function(int, scope) {
//Add the Netscript environment
var ns = NetscriptFunctions(workerScript);
for (var name in ns) {
for (let name in ns) {
let entry = ns[name];
if (typeof entry === "function") {
//Async functions need to be wrapped. See JS-Interpreter documentation
@ -182,10 +182,23 @@ function startNetscript1Script(workerScript) {
}
int.setProperty(scope, name, int.createAsyncFunction(tempWrapper));
} else {
int.setProperty(scope, name, int.createNativeFunction(entry));
let tempWrapper = function() {
let res = entry.apply(null, arguments);
if (res == null) {
return res;
} else if (res.constructor === Array || (res === Object(res))) {
//Objects and Arrays must be converted to the interpreter's format
console.log("Function returning object detected: " + name);
return int.nativeToPseudo(res);
} else {
return res;
}
}
int.setProperty(scope, name, int.createNativeFunction(tempWrapper));
}
} else {
//Math, Date, Number, hacknetnodes, bladeburner
//bladeburner, or anything else
int.setProperty(scope, name, int.nativeToPseudo(entry));
}
}
@ -193,7 +206,16 @@ function startNetscript1Script(workerScript) {
//Add the arguments
int.setProperty(scope, "args", int.nativeToPseudo(workerScript.args));
}
var interpreter = new Interpreter(code, interpreterInitialization);
var interpreter;
try {
interpreter = new Interpreter(code, interpreterInitialization);
} catch(e) {
dialogBoxCreate("Syntax ERROR in " + workerScript.name + ":<br>" + e);
workerScript.env.stopFlag = true;
workerScript.running = false;
return;
}
return new Promise(function(resolve, reject) {
function runInterpreter() {
@ -217,7 +239,18 @@ function startNetscript1Script(workerScript) {
}
}
runInterpreter();
try {
runInterpreter();
} catch(e) {
if (isString(e)) {
workerScript.errorMessage = e;
return reject(workerScript);
} else if (e instanceof WorkerScript) {
return reject(e);
} else {
return reject(workerScript);
}
}
});
@ -274,6 +307,7 @@ function runScriptsLoop() {
p = startNetscript2Script(workerScripts[i]);
} else {
p = startNetscript1Script(workerScripts[i]);
if (!(p instanceof Promise)) {continue;}
/*
try {
var ast = parse(workerScripts[i].code, {sourceType:"module"});

@ -2,7 +2,7 @@ import {Engine} from "./engine";
/* Settings.js */
let Settings = {
CodeInstructionRunTime: 50,
CodeInstructionRunTime: 25,
MaxLogCapacity: 50,
MaxPortCapacity: 50,
SuppressMessages: false,