js-slang
Version:
Javascript-based implementations of Source, written in Typescript
54 lines • 1.84 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolvedErrorPromise = exports.determineExecutionMethod = exports.determineVariant = void 0;
const inspector_1 = require("../stdlib/inspector");
const walkers_1 = require("../utils/walkers");
// Context Utils
/**
* Small function to determine the variant to be used
* by a program, as both context and options can have
* a variant. The variant provided in options will
* have precedence over the variant provided in context.
*
* @param context The context of the program.
* @param options Options to be used when
* running the program.
*
* @returns The variant that the program is to be run in
*/
function determineVariant(context, options) {
if (options.variant) {
return options.variant;
}
else {
return context.variant;
}
}
exports.determineVariant = determineVariant;
function determineExecutionMethod(theOptions, context, program, verboseErrors) {
if (theOptions.executionMethod !== 'auto') {
context.executionMethod = theOptions.executionMethod;
return;
}
if (context.executionMethod !== 'auto') {
return;
}
let isNativeRunnable;
if (verboseErrors || (0, inspector_1.areBreakpointsSet)()) {
isNativeRunnable = false;
}
else {
let hasDebuggerStatement = false;
(0, walkers_1.simple)(program, {
DebuggerStatement() {
hasDebuggerStatement = true;
}
});
isNativeRunnable = !hasDebuggerStatement;
}
context.executionMethod = isNativeRunnable ? 'native' : 'cse-machine';
}
exports.determineExecutionMethod = determineExecutionMethod;
// AST Utils
exports.resolvedErrorPromise = Promise.resolve({ status: 'error' });
//# sourceMappingURL=utils.js.map
;