Skip to content

Commit 6f28006

Browse files
committed
ISSUE-2: VMEmulator built-in classes not useable from command line
The use of built-in classes is now controlled by the environment variable N2T_VM_USE_BUILTINS. If set to "yes" (case insesitive), the built-in classes will be used without prompting. If set to "no", the built-in classes won't be used (again, no prompting). In any other case, we'll fallback to the previous behaviour. That is, prompt for GUI and reject for CLI.
1 parent 73e5bec commit 6f28006

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

SimulatorsPackage/src/main/java/Hack/VMEmulator/CPU.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,9 @@ public CPU(VMProgram program, RAM ram, CallStack callStack,
108108

109109
stackFrames = new Vector<Integer>();
110110

111-
if (program.getGUI() != null) {
112-
builtInFunctionsRunner =
113-
new BuiltInFunctionsRunner(this, builtInDir);
114-
}
111+
final boolean useBuiltIns = "yes".equalsIgnoreCase(System.getenv("N2T_VM_USE_BUILTINS"));
112+
if (useBuiltIns || program.getGUI() != null)
113+
builtInFunctionsRunner = new BuiltInFunctionsRunner(this, builtInDir);
115114
}
116115

117116
/**

SimulatorsPackage/src/main/java/Hack/VMEmulator/VMProgram.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,11 @@ public short getAddress(String functionName) throws ProgramException {
557557
// this as this is not a feature from the book but a later
558558
// addition.
559559
if (builtInAccessStatus == BUILTIN_ACCESS_UNDECIDED) {
560-
if (hasGUI && gui.confirmBuiltInAccess()) {
561-
builtInAccessStatus = BUILTIN_ACCESS_AUTHORIZED;
562-
} else {
563-
builtInAccessStatus = BUILTIN_ACCESS_DENIED;
564-
}
565-
}
560+
final String envUseBuiltIns = System.getenv("N2T_VM_USE_BUILTINS");
561+
final boolean useBuiltIns = "yes".equalsIgnoreCase(envUseBuiltIns)
562+
|| (!"no".equalsIgnoreCase(envUseBuiltIns) && hasGUI && gui.confirmBuiltInAccess());
563+
builtInAccessStatus = useBuiltIns ? BUILTIN_ACCESS_AUTHORIZED : BUILTIN_ACCESS_DENIED;
564+
}
566565
if (builtInAccessStatus == BUILTIN_ACCESS_AUTHORIZED) {
567566
return BUILTIN_FUNCTION_ADDRESS;
568567
}

0 commit comments

Comments
 (0)