static void compile_and_run_action(frameact action, u8 **ffp, u8 **fsp) { struct compile_and_run_frame *frame = (struct compile_and_run_frame *)*ffp; switch (action) { case fa_execute: switch (frame->state) { case running: { value result = stack_get(0); end_run(frame, module_loaded); /* Done. Pop frame */ FA_POP(&fp, &sp); stack_push(result); break; } case preparing: mprepare_load_next_done(&frame->ps); continue_prepare(frame); break; default: abort(); } break; case fa_print: /* It's nicer without a message here */ /*mputs("<compile>", muderr);*/ break; case fa_unwind: if (frame->state != init) end_run(frame, module_error); goto pop; case fa_gcforward: forward((value *)&frame->ps.ccontext); /* fall through */ case fa_pop: pop: pop_frame(ffp, fsp, sizeof(struct compile_and_run_frame)); break; default: abort(); } }
int main(int argc, char **argv) { parse_args(argc, argv); float res = price(n); printf("Price is: %f\n", res); for (int i = 0; i < runs; i++) { start_run(); res = price(n); end_run(); printf("Price is: %f\n", res); } }
int main(int argc, char *argv[]) { int master_fd, op, status; pid_t pid, run_pid; sv cmd; fd_set readfds; struct timeval tout; if (argc != 2) errx(1, "Need socket directory argument"); master_fd = hookup(argv[1]); initscr(); signal(SIGWINCH, sig_winch); nonl(); cbreak(); noecho(); for ( ; ; ) { update_display(); FD_ZERO(&readfds); FD_SET(master_fd, &readfds); gettimeofday(&tout, NULL); tout.tv_sec = 0; tout.tv_usec = 1050000-tout.tv_usec; if (select(master_fd+1, &readfds, NULL, NULL, &tout) < 0) { if (errno == EINTR) continue; err(4, "select"); } if (!FD_ISSET(master_fd, &readfds)) continue; readn(master_fd, &op, sizeof (int)); if (op == TOP_OP_EXIT) break; switch (op) { case TOP_OP_FETCH: read_sv(master_fd, &cmd); init_run(&cmd); break; case TOP_OP_ISSUE: readn(master_fd, &pid, sizeof (pid_t)); readn(master_fd, &run_pid, sizeof (pid_t)); start_run(pid, run_pid); break; case TOP_OP_DONE: readn(master_fd, &run_pid, sizeof (pid_t)); end_run(run_pid, 0); break; case TOP_OP_ATTN: readn(master_fd, &run_pid, sizeof (pid_t)); readn(master_fd, &status, sizeof (pid_t)); end_run(run_pid, status); break; case TOP_OP_ONLINE: sc++; break; case TOP_OP_OFFLINE: sc--; break; default: errx(5, "Unknown opcode %d", op); } } endwin(); return 0; }