int main (int argc, char *argv[]) { printf("PROTO v%s%s (Kernel %s) (Developed by MIT Space-Time Programming Group 2005-2008)\n", PROTO_VERSION, "[opsim]", KERNEL_VERSION); Args *args = new Args(argc,argv); // set up the arg parser // define color palette #ifdef WANT_GLUT palette = Palette::default_palette; #endif //WANT_GLUT computer = new SpatialComputer(args,!test_mode); // then the computer int len = -1; if(args->argc <= 0) FATAL("Insufficient arguments"); uint8_t* s = read_script(args->argv[args->argc-1],&len); if(len > 0 && s != NULL) computer->load_script(s,len); cout << "DONE load_script." << endl; // and start! bool headless = args->extract_switch("-headless") || DEFAULT_HEADLESS; if(args->extract_switch("-stop-after")) stop_time = args->pop_number(); computer->is_dump = true; computer->is_debug = true; computer->dump_period = stop_time-1; if(headless) { if(stop_time==INFINITY) uerror("Headless runs must set an end time with -stop-after N"); while(1) idle(); } cout << "Exiting OPSIM." << endl; }
int main (int argc, char *argv[]) { post("PROTO v%s%s (%s) (Developed by MIT Space-Time Programming Group 2005-2008)\n", PROTO_VERSION, #if USE_NEOCOMPILER "[neo]", #else "[paleo]", #endif KERNEL_VERSION); Args *args = new Args(argc,argv); // set up the arg parser // initialize randomness [JAH: fmod added for OS X bug] unsigned int seed = (unsigned int) (args->extract_switch("-seed") ? args->pop_number() : fmod(get_real_secs()*1000, RAND_MAX)); post("Using random seed %d\n", seed); srand(seed); process_app_args(args); bool headless = args->extract_switch("-headless") || DEFAULT_HEADLESS; if(!headless) { vis = new Visualizer(args); // start visualizer } else { #ifdef WANT_GLUT palette = Palette::default_palette; #endif // WANT_GLUT } computer = new SpatialComputer(args,!test_mode); if(opcode_file != "") { post("reading opcodes from: %s\n", opcode_file.c_str()); // read from file int len = -1; uint8_t* s = read_script(opcode_file,&len); //post("script[%d]=\n",len); //for(unsigned int i=0; i<len; ++i) // post("%d\n", s[i]); if(len > 0 && s != NULL) { computer->load_script(s,len); } else uerror("Problem loading opcode file: %s", opcode_file.c_str()); if(!headless) { vis->set_bounds(computer->vis_volume); // connect to computer register_app_colors(); } } else { // use a compiler #if USE_NEOCOMPILER compiler = new NeoCompiler(args); // first the compiler compiler->emitter = new ProtoKernelEmitter(compiler,args); #else compiler = new PaleoCompiler(args); // first the compiler #endif string defops; computer->appendDefops(defops); compiler->setDefops(defops); if(!headless) { vis->set_bounds(computer->vis_volume); // connect to computer register_app_colors(); } // next the forwarder for the motes, if desired if(args->extract_switch("-motelink")) motelink = new MoteLink(args); // load the script int len; if(args->argc==1) { uerror("No program specified: all arguments consumed."); } else { uint8_t* s = compiler->compile(args->argv[args->argc-1],&len); computer->load_script(s,len); if(args->argc>2) { post("WARNING: %d unhandled arguments:",args->argc-2); for(int i=2;i<args->argc;i++) post(" '%s'",args->argv[i-1]); post("\n"); } } } // if in test mode, swap the C++ file for a C file for the SpatialComputer if(test_mode) { delete cpout; computer->dump_file = fopen(dump_name,"a"); } // and start! if(headless) { if(stop_time==INFINITY) uerror("Headless runs must set an end time with -stop-after N"); while(1) idle(); } else { #ifdef WANT_GLUT // set up callbacks for user interface and idle glutMouseFunc(on_mouse_button); glutMotionFunc(on_mouse_motion); glutPassiveMotionFunc(on_mouse_motion); glutDisplayFunc(render); glutReshapeFunc(resize); glutIdleFunc(idle); glutKeyboardFunc(keyboard_handler); glutSpecialFunc(special_handler); // finally, hand off control to the glut event-loop glutMainLoop(); #endif } }