Fixed numerous reported bugs. Refactored some of the directory-related code. Added documentation for MasonDs changes to hack/grow/weaken

This commit is contained in:
danielyxie
2019-05-11 19:20:20 -07:00
parent 29e0ce5f96
commit b0918d7bd3
19 changed files with 172 additions and 88 deletions
+8 -7
View File
@@ -1,6 +1,8 @@
// Calculate a script's RAM usage
import * as walk from "acorn-walk";
import { RamCalculationErrorCode } from "./RamCalculationErrorCodes";
import { RamCosts, RamCostConstants } from "../Netscript/RamCostGenerator";
import { parse, Node } from "../../utils/acorn";
@@ -71,12 +73,12 @@ async function parseOnlyRamCalculate(otherScripts, code, workerScript) {
}
} catch(e) {
console.error(`Error dynamically importing module from ${nextModule} for RAM calculations: ${e}`);
return -1;
return RamCalculationErrorCode.URLImportError;
}
} else {
if (!Array.isArray(otherScripts)) {
console.warn(`parseOnlyRamCalculate() not called with array of scripts`);
return -1;
return RamCalculationErrorCode.ImportError;
}
let script = null;
@@ -89,8 +91,7 @@ async function parseOnlyRamCalculate(otherScripts, code, workerScript) {
}
if (script == null) {
console.warn("Invalid script");
return -1; // No such script on the server.
return RamCalculationErrorCode.ImportError; // No such script on the server
}
code = script.code;
@@ -191,7 +192,7 @@ async function parseOnlyRamCalculate(otherScripts, code, workerScript) {
// console.info("parse or eval error: ", error);
// This is not unexpected. The user may be editing a script, and it may be in
// a transitory invalid state.
return -1;
return RamCalculationErrorCode.SyntaxError;
}
}
@@ -310,8 +311,8 @@ export async function calculateRamUsage(codeCopy, otherScripts) {
} catch (e) {
console.error(`Failed to parse script for RAM calculations:`);
console.error(e);
return -1;
return RamCalculationErrorCode.SyntaxError;
}
return -1;
return RamCalculationErrorCode.SyntaxError;
}