12 #define DEFAULT_LIMIT 500000
14 static int usage(
char * argv[]) {
15 fprintf(stderr,
"usage: %s [-s COUNT] [-q] FILE [args...]\n", argv[0]);
19 static int help(
char * argv[]) {
22 "Run scripts with an instruction counter and halt when a "
23 "limit is exceeded. The default limit is %d. A total count of "
24 "executed instructions is printed after completion.\n"
27 " -s COUNT Set watchdog timeout to COUNT instructions.\n"
28 " Specify -1 to set disable limit.\n"
29 " -q Do not print total instruction count.\n"
31 " --help Show this help text.\n"
38 static size_t instrCounter = 0;
39 static size_t stopAt = DEFAULT_LIMIT;
44 if (instrCounter < stopAt)
return KRK_DEBUGGER_STEP;
45 if (instrCounter == stopAt) {
48 return KRK_DEBUGGER_CONTINUE;
52 int main(
int argc,
char *argv[]) {
54 while ((opt = getopt(argc, argv,
"+:s:q-:")) != -1) {
57 stopAt = strtoul(optarg,NULL,10);
64 fprintf(stderr,
"%s: unrocognized option '%c'\n", argv[0], optopt);
67 optarg = argv[optind]+1;
70 if (!strcmp(optarg,
"help")) {
73 fprintf(stderr,
"%s: unrecognized option: '--%s'\n", argv[0], optarg);
83 findInterpreter(argv);
92 fprintf(stderr,
"%zu total instructions\n", instrCounter);
Functions for debugging bytecode execution.
int krk_debug_registerCallback(KrkDebugCallback hook)
Register a debugger callback.
KrkValue krk_runtimeError(KrkClass *type, const char *fmt,...)
Produce and raise an exception with a formatted message.
Top-level header with configuration macros.
Represents a managed call state in a VM thread.
void krk_freeVM(void)
Release resources from the VM.
void krk_initVM(int flags)
Initialize the VM at program startup.
Utilities for creating native bindings.
Core API for the bytecode virtual machine.
#define vm
Convenience macro for namespacing.
KrkValue krk_runfile(const char *fileName, const char *fromFile)
Load and run a source file and return when execution completes.
KrkInstance * krk_startModule(const char *name)
Set up a new module object in the current thread.