mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-05 07:07:50 +02:00
Fixed new Netscript1 Interpreter to work for functions returning Arrays/Objets. Untested. Also still needs new Hacknet Node implementation
This commit is contained in:
Vendored
+3649
-145
File diff suppressed because one or more lines are too long
Vendored
+1
-3874
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -809,7 +809,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</label>
|
</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>
|
<em id="settingsNSExecTimeRangeValLabel" style="font-style: normal;"></em>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|||||||
+3592
-136
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 " +
|
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");
|
"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="") {
|
getActionTime : function(type="", name="") {
|
||||||
if (workerScript.checkingRam) {
|
if (workerScript.checkingRam) {
|
||||||
return updateStaticRam("getActionTime", CONSTANTS.ScriptBladeburnerApiBaseRamCost);
|
return updateStaticRam("getActionTime", CONSTANTS.ScriptBladeburnerApiBaseRamCost);
|
||||||
|
|||||||
+39
-5
@@ -163,7 +163,7 @@ function startNetscript1Script(workerScript) {
|
|||||||
var interpreterInitialization = function(int, scope) {
|
var interpreterInitialization = function(int, scope) {
|
||||||
//Add the Netscript environment
|
//Add the Netscript environment
|
||||||
var ns = NetscriptFunctions(workerScript);
|
var ns = NetscriptFunctions(workerScript);
|
||||||
for (var name in ns) {
|
for (let name in ns) {
|
||||||
let entry = ns[name];
|
let entry = ns[name];
|
||||||
if (typeof entry === "function") {
|
if (typeof entry === "function") {
|
||||||
//Async functions need to be wrapped. See JS-Interpreter documentation
|
//Async functions need to be wrapped. See JS-Interpreter documentation
|
||||||
@@ -182,10 +182,23 @@ function startNetscript1Script(workerScript) {
|
|||||||
}
|
}
|
||||||
int.setProperty(scope, name, int.createAsyncFunction(tempWrapper));
|
int.setProperty(scope, name, int.createAsyncFunction(tempWrapper));
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
//Math, Date, Number, hacknetnodes, bladeburner
|
//bladeburner, or anything else
|
||||||
int.setProperty(scope, name, int.nativeToPseudo(entry));
|
int.setProperty(scope, name, int.nativeToPseudo(entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,7 +206,16 @@ function startNetscript1Script(workerScript) {
|
|||||||
//Add the arguments
|
//Add the arguments
|
||||||
int.setProperty(scope, "args", int.nativeToPseudo(workerScript.args));
|
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) {
|
return new Promise(function(resolve, reject) {
|
||||||
function runInterpreter() {
|
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]);
|
p = startNetscript2Script(workerScripts[i]);
|
||||||
} else {
|
} else {
|
||||||
p = startNetscript1Script(workerScripts[i]);
|
p = startNetscript1Script(workerScripts[i]);
|
||||||
|
if (!(p instanceof Promise)) {continue;}
|
||||||
/*
|
/*
|
||||||
try {
|
try {
|
||||||
var ast = parse(workerScripts[i].code, {sourceType:"module"});
|
var ast = parse(workerScripts[i].code, {sourceType:"module"});
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ import {Engine} from "./engine";
|
|||||||
|
|
||||||
/* Settings.js */
|
/* Settings.js */
|
||||||
let Settings = {
|
let Settings = {
|
||||||
CodeInstructionRunTime: 50,
|
CodeInstructionRunTime: 25,
|
||||||
MaxLogCapacity: 50,
|
MaxLogCapacity: 50,
|
||||||
MaxPortCapacity: 50,
|
MaxPortCapacity: 50,
|
||||||
SuppressMessages: false,
|
SuppressMessages: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user