#include #include "Publishing/edition.h" #include "assert.h" #include "commandline/parameters.h" #include "cstring.h" #include "errors/errors.h" #include "errors/exceptions.h" #include "errors/handle.h" #include "errors/report.h" #include "files/files.h" #include "interpreter/start.h" #include "memory/virtualmemory.h" #include "object.h" #include "stacks.h" #include "types/boolean.h" #include "types/composites/composites.h" #include "types/equality.h" #include "types/numbers/integer.h" static const configure defaults = { .DebugLevel = integerconstant(0), .ExecutionMode = stringliteral("autodetect"), .FileName = stringliteral("%stdin"), .MaxDictStack = integerconstant(16), .MaxExecStack = integerconstant(64), .MaxGlobalVM = integerconstant(32 MB), .MaxLocalVM = integerconstant(128 MB), .MaxOpStack = integerconstant(512), .StartJobPassword = stringliteral(""), .SystemParamsPassword = stringliteral(""), .VMFileName = stringliteral(""), .exec = stringliteral(""), .osFileAccess = stringliteral("readonly"), .startup = stringliteral(""), .termination = stringliteral("") }; static natural size(const object integer) { assert(integer.type == integertype); assert(integer.integer >= 0); return (natural)integer.integer; } int main(const int number, cstring const parameters[]) { if (number) { assert(number > 0); assert(parameters); } if (number == 0 || parameters[0][0] == '\0') parameters = (cstring const []){edition.title, 0}; configure interpreter = commandlineparameters(parameters, defaults); if (interpreter.error) exit(EXIT_FAILURE); assert(interpreter.DebugLevel.type == integertype); reporterrors = (interpreter.DebugLevel.integer >= 1); stacktrace = (interpreter.DebugLevel.integer >= 2); volatile int exitstatus = EXIT_FAILURE; try { limit(operandstack, size(interpreter.MaxOpStack)); limit(executionstack, size(interpreter.MaxExecStack)); limit(dictionarystack, size(interpreter.MaxDictStack)); if (eq(interpreter.ExecutionMode, string("autodetect"))) { if (eq(interpreter.FileName, string("%stdin")) && terminal(stdin)) interpreter.ExecutionMode = string("interactive"); else interpreter.ExecutionMode = string("minimal"); } if (start(interpreter)) exitstatus = EXIT_SUCCESS; } else { report(exception); } then { try { flushfile(stdout); destroy(operandstack); destroy(executionstack); destroy(dictionarystack); } else { report(exception); exitstatus = EXIT_FAILURE; } then { exit(exitstatus); } } }