int main(int argc, char** argv) { vm_init(); // Test mode if (argc == 2 && strcmp(argv[1], "--test") == 0) { test_vm(); test_parser(); test_interp(); return 0; } // File name passed if (argc == 2) { char* cstr = read_file(argv[1]); if (cstr == NULL) return -1; // Evaluate the code string eval_str(cstr); free(cstr); } // No file names passed. Read-eval-print loop. if (argc == 1) { run_repl(); } return 0; }
bool Debugger::poll() { update_history(); if(mode == STEP || check_jump_condition() || check_brpt_condition()) { mode = STEP; return run_repl(); } return true; }
int main(int argc, char** argv) { char* filename = NULL; int repl_flag=0, help_flag=0; struct option long_opts[] = { {"help", no_argument, &help_flag, 1}, {"repl", no_argument, &repl_flag, 1}, {0, 0, 0, 0} }; int cont = 1; while(cont) { int opt_index = 0; switch(getopt_long(argc, argv, "hr", long_opts, &opt_index)) { case -1: cont = 0; break; case 'r': repl_flag = 1; break; case '?': case 'h': return usage(); } } if(optind < argc) filename = argv[optind++]; if((!filename && !repl_flag) || help_flag) return usage(); context* root = context_create(); root->scope = scope_create(NULL); if(filename) run_file(filename, root); if(repl_flag) run_repl(root); context_destroy(root); return 0; }
int main(int argc, void* argv) { sigset_t emptyset; // sigsegv_init(&ss_dispatcher); sigsegv_install_handler(ss_handler); /* Save the current signal mask. */ sigemptyset (&emptyset); sigprocmask (SIG_BLOCK, &emptyset, &mainsigset); enable_memory_block(&Vm_image_start, &Vm_image_end); process_opts(argc,argv); install_exception_handler(kernel_exception_handler); if ( opts.image_file != 0 ) load_image(opts.image_file); run_repl(); return 0; }
bool Debugger::run_repl() { fmt::print_prompt(c, *mmu); switch(inp::get<char>("%c")) { case 'r': mode = RUN; return true; case 'x': print_cpu_status(std::cout); return run_repl(); case 'g': print_gpu_status(std::cout); return run_repl(); case 'h': print_ghw_status(std::cout); return run_repl(); case '+': set_breakpoint(); return run_repl(); case '-': rem_breakpoint(); return run_repl(); case 'i': inspect(std::cout); return run_repl(); case 'l': print_history(std::cout); return run_repl(); case 'q': return false; case '?': { std::cout << "Interactive debugger:" << std::endl << std::endl;; std::cout << "(Press ESC while running to enter STEP-Mode)" << std::endl << std::endl; std::cout << " 'r': Run programm" << std::endl; std::cout << " 'x': Show cpu status" << std::endl; std::cout << " 'g': Show gpu status" << std::endl; std::cout << " 'h': Show general hadware status" << std::endl; std::cout << " '+': Add breakpoint" << std::endl; std::cout << " '-': List/Remove breakpoints" << std::endl; std::cout << " 'i': Inspect memory" << std::endl; std::cout << " 'l': List history" << std::endl; std::cout << " 'q': Quit program" << std::endl; std::cout << " Enter: Step" << std::endl << std::endl; return run_repl(); } default: return true; } return true; }
int main(int argc, char *argv[]) { CORD input = NULL; const char *in_file_name = NULL; FILE *in_file = NULL; Module *state = NULL; int opt; int disassemble = 0; const char *func = "main"; int interactive = 0; int listing = 0; while((opt = getopt(argc, argv, "lhdf:i")) != -1) { switch(opt) { case 'd': disassemble = 1; break; case 'f': func = optarg; break; case 'i': interactive = 1; break; case 'l': listing = 1; break; case 'h': /// fall through! default: die(NULL, "USAGE: earing [-d | -i] [-f function] <file.asm>\n"); return 1; } } if(optind >= argc) { die(NULL, "You have to give a file. Use -h to see the usage."); return 1; } GC_INIT(); in_file_name = argv[optind]; in_file = fopen(in_file_name, "r"); if(!in_file) { die(NULL, "Failed to open the input file %s", in_file_name); } input = CORD_from_file(in_file); state = Module_create(in_file_name, 1024); Module_register_default_directives(state); if(!Module_compile(state, CORD_to_const_char_star(input), CORD_len(input))) { die(state, "Parsing failed with %d errors.\n", state->errors); return 1; } else { if(listing) { tst_traverse(state->functions, (tst_traverse_cb)query_functions, NULL); } else if(disassemble) { dis_functions(state); } else if(interactive) { // go into interactive mode with the repl run_repl(state, in_file_name); } else { // run the given function or the "main" default run_function(state, func); } } return 0; }
int main(int argc, char **argv) { config.verbose = false; config.quiet = false; config.repl = false; config.javascript = false; config.static_fns = false; config.elide_asserts = false; config.cache_path = NULL; config.theme = "light"; config.dumb_terminal = false; config.out_path = NULL; config.num_src_paths = 0; config.src_paths = NULL; config.num_scripts = 0; config.scripts = NULL; config.main_ns_name = NULL; struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"legal", no_argument, NULL, 'l'}, {"verbose", no_argument, NULL, 'v'}, {"quiet", no_argument, NULL, 'q'}, {"repl", no_argument, NULL, 'r'}, {"static-fns", no_argument, NULL, 's'}, {"elide-asserts", no_argument, NULL, 'a'}, {"cache", required_argument, NULL, 'k'}, {"eval", required_argument, NULL, 'e'}, {"theme", required_argument, NULL, 't'}, {"dumb-terminal", no_argument, NULL, 'd'}, {"classpath", required_argument, NULL, 'c'}, {"auto-cache", no_argument, NULL, 'K'}, {"init", required_argument, NULL, 'i'}, {"main", required_argument, NULL, 'm'}, // development options {"javascript", no_argument, NULL, 'j'}, {"out", required_argument, NULL, 'o'}, {0, 0, 0, 0} }; int opt, option_index; while ((opt = getopt_long(argc, argv, "h?lvrsak:je:t:dc:o:Ki:qm:", long_options, &option_index)) != -1) { switch (opt) { case 'h': usage(argv[0]); exit(0); case 'l': legal(); return 0; case 'v': config.verbose = true; break; case 'q': config.quiet = true; break; case 'r': config.repl = true; break; case 's': config.static_fns = true; break; case 'a': config.elide_asserts = true; break; case 'k': config.cache_path = argv[optind - 1]; break; case 'K': config.cache_path = ".planck_cache"; { char *path_copy = strdup(config.cache_path); char *dir = dirname(path_copy); if (mkdir_p(dir) < 0) { fprintf(stderr, "Could not create %s: %s\n", config.cache_path, strerror(errno)); } free(path_copy); } break; case 'j': config.javascript = true; break; case 'e': config.num_scripts += 1; config.scripts = realloc(config.scripts, config.num_scripts * sizeof(struct script)); config.scripts[config.num_scripts - 1].type = "text"; config.scripts[config.num_scripts - 1].expression = true; config.scripts[config.num_scripts - 1].source = argv[optind - 1]; break; case 'i': config.num_scripts += 1; config.scripts = realloc(config.scripts, config.num_scripts * sizeof(struct script)); config.scripts[config.num_scripts - 1].type = "path"; config.scripts[config.num_scripts - 1].expression = false; config.scripts[config.num_scripts - 1].source = argv[optind - 1]; break; case 'm': config.main_ns_name = argv[optind - 1]; break; case 't': config.theme = argv[optind - 1]; break; case 'd': config.dumb_terminal = true; break; case 'c': { char *classpath = argv[optind - 1]; char *source = strtok(classpath, ":"); while (source != NULL) { char *type = "src"; if (str_has_suffix(source, ".jar") == 0) { type = "jar"; } config.num_src_paths += 1; config.src_paths = realloc(config.src_paths, config.num_src_paths * sizeof(struct src_path)); config.src_paths[config.num_src_paths - 1].type = type; config.src_paths[config.num_src_paths - 1].path = strcmp(type, "jar") == 0 ? strdup(source) : ensure_trailing_slash(source); source = strtok(NULL, ":"); } break; } case 'o': config.out_path = ensure_trailing_slash(argv[optind - 1]); break; case '?': usage(argv[0]); exit(1); default: printf("unhandled argument: %c\n", opt); } } if (config.dumb_terminal) { config.theme = "dumb"; } config.num_rest_args = 0; config.rest_args = NULL; if (optind < argc) { config.num_rest_args = argc - optind; config.rest_args = malloc((argc - optind) * sizeof(char*)); int i = 0; while (optind < argc) { config.rest_args[i++] = argv[optind++]; } } if (config.num_scripts == 0 && config.main_ns_name == NULL && config.num_rest_args == 0) { config.repl = true; } if (config.main_ns_name != NULL && config.repl) { printf("Only one main-opt can be specified.\n"); exit(1); } config.is_tty = isatty(STDIN_FILENO) == 1; JSGlobalContextRef ctx = JSGlobalContextCreate(NULL); global_ctx = ctx; cljs_engine_init(ctx); // Process init arguments for (int i = 0; i < config.num_scripts; i++) { // TODO: exit if not successfull struct script script = config.scripts[i]; evaluate_source(ctx, script.type, script.source, script.expression, false, NULL, config.theme, true); } // Process main arguments if (config.main_ns_name != NULL) { run_main_in_ns(ctx, config.main_ns_name, config.num_rest_args, config.rest_args); } else if (!config.repl && config.num_rest_args > 0) { char *path = config.rest_args[0]; struct script script; if (strcmp(path, "-") == 0) { char *source = read_all(stdin); script.type = "text"; script.source = source; script.expression = false; } else { script.type = "path"; script.source = path; script.expression = false; } evaluate_source(ctx, script.type, script.source, script.expression, false, NULL, config.theme, true); } else if (config.repl) { if (!config.quiet) { banner(); } run_repl(ctx); } return exit_value; }