/** execute_declared_subroutine_call Execute a call to a declared * procedure or function. * * @param p_function_id : ptr to the subroutine name's symtab node * * @return: ptr to the call's type object */ cx_type *cx_executor::execute_declared_subroutine_call (cx_symtab_node *p_function_id) { int old_level = current_nesting_level; // level of caller int new_level = p_function_id->level + 1; // level of callee's locals // Set up a new stack frame for the callee. cx_frame_header *p_new_frame_base = run_stack.push_frame_header (old_level, new_level, p_icode); // push actual parameter values onto the stack. get_token(); if (token == tc_left_paren) { execute_actual_parameters(p_function_id); } // ) get_token(); // Activate the new stack frame ... current_nesting_level = new_level; run_stack.activate_frame(p_new_frame_base, current_location() - 1); // ... and execute the callee. execute_routine(p_function_id); // Return to the caller. Restore the current token. current_nesting_level = old_level; get_token(); return p_function_id->p_type; }
/** execute_FOR Executes for statement. * initialize condition increment * for(<statement>; <expression>; <expression>) * <statement>; * * @param p_function_id */ void cx_executor::execute_FOR(cx_symtab_node * p_function_id) { bool condition = false; get_token(); // for // get the location of where to go to if <expr> is false. int break_point = get_location_marker(); get_token(); int statement_location = get_location_marker(); get_token(); int condition_marker = get_location_marker(); get_token(); int increment_marker = get_location_marker(); get_token(); // ( get_token(); if (token != tc_semicolon) { // declaration would go here // execute_assignment(p_node); } do { get_token(); // ; if (token != tc_semicolon) { // expr 2 execute_expression(); get_token(); // ; } else get_token(); condition = top()->basic_types.bool__; pop(); if (condition) { go_to(statement_location); get_token(); execute_statement(p_function_id); if (break_loop) go_to(break_point); } else { go_to(break_point); get_token(); break; } go_to(increment_marker); get_token(); // expr 3 execute_expression(); go_to(condition_marker); } while (current_location() == condition_marker); break_loop = false; }
static void rcc_aborting(int s) { location where; signal(SIGABRT, 0); fprintf(stderr, "nesC: Internal error. Please send a bug report to the nesC bug mailing list\nat [email protected]\n"); where = current_location(); if (where != dummy_location) fprintf(stderr, "Current location (guess): %s:%lu\n", where->filename, where->lineno); if (getenv("RCCDEBUG")) abort(); else exit(FATAL_EXIT_CODE); }
static void rcc_aborting(int s) { location where; signal(SIGABRT, 0); fprintf(stderr, "nesC: Internal error.\n" "Please submit an issue to the GitHub repository at https://github.com/tinyos/nesc\n"); where = current_location(); if (where != dummy_location) fprintf(stderr, "Current location (guess): %s:%lu\n", where->filename, where->lineno); if (getenv("RCCDEBUG")) abort(); else exit(FATAL_EXIT_CODE); }
static int i386_intel_parse_name (const char *name, expressionS *e) { unsigned int j; if (! strcmp (name, "$")) { current_location (e); return 1; } for (j = 0; i386_types[j].name; ++j) if (strcasecmp(i386_types[j].name, name) == 0) { e->X_op = O_constant; e->X_add_number = i386_types[j].sz[flag_code]; e->X_add_symbol = NULL; e->X_op_symbol = NULL; return 1; } return 0; }
void compute_automount_point(char *buf, size_t l, host *hp, char *vn) { xsnprintf(buf, l, "%s/%s%s", autodir, hp->h_lochost, vn); } /* * Data constructors.. */ automount * new_automount(char *name) { automount *ap = CALLOC(struct automount); ap->a_ioloc = current_location(); ap->a_name = name; ap->a_volname = NULL; ap->a_mount = NULL; ap->a_opts = NULL; show_new("automount"); return ap; } auto_tree * new_auto_tree(char *def, qelem *ap) { auto_tree *tp = CALLOC(struct auto_tree); tp->t_ioloc = current_location();
int main(void) { m_clockdivide(0); // clock speed 16 MHz sei(); // enable global interrups int derivative = 0; // initialize m_bus communications // start wireless communications // and open wii camera m_bus_init(); m_wii_open(); m_usb_init(); m_rf_open(CHANNEL, RXADDRESS, PACKET_LENGTH); setup(); // motor setup int side; // integer to figure out which side we're on while (1) { // USB print testing m_usb_tx_string("testing: "); m_usb_tx_int(testing); m_usb_tx_string(" "); m_usb_tx_string("\n"); // continue code if ply command is issued if ((unsigned char)buffer1[0] == 0xA1){ break; } } // turn red light on if play command is issued m_red(ON); // wait 10 seconds to let M_Wii start recording stars m_wait(1000); int position[3]; // array for robot position int x1; // x position int i; // calculate initial positions for(i = 0; i<1000; i++) { current_location(position); x1 = position[0]; } // figure out what side robot starts on if (x1 > 0) { side = -1; } else { side = 1; } // array to hold constants float constants[4]; //goal(); // main LOOP while(1) { // calculate positions int b = current_location(position); int x1 = position[0]; int y1 = position[1]; int angle = position[2]; // usb prinitng m_usb_tx_string("LOCALIZATION: "); m_usb_tx_int(b); m_usb_tx_string(" "); m_usb_tx_string("X Position: "); m_usb_tx_int(x1); m_usb_tx_string(" "); m_usb_tx_string("Y Position: "); m_usb_tx_int(y1); m_usb_tx_string(" "); m_usb_tx_string("Angle: "); m_usb_tx_int(angle); m_usb_tx_string(" "); m_usb_tx_string("\n"); // get constants if (side>0){ get_constants1(constants, -115, 0, x1, y1, angle, side, derivative); } else { get_constants1(constants, 115, 0, x1, y1, angle, side, derivative); } float p = constants[0]; // speed constant int d = (int)constants[1]; // direction constant float j = constants[2]; // how much turn constant derivative = constants[3]; turn_robot( d, 1, .9, j); // DRIVE THE BOT } }
//c7 red /// e6 blue int main(void) { m_disableJTAG(); // Turn off JTAG //m_red(ON); // check code runs m_clockdivide(0); // clock speed 16 MHz m_bus_init(); // initialize m_bus communications m_usb_init(); // USB COM setup(); // motor setup ADC_setup(); // setup anlog conversions // start wireless communications m_rf_open(CHANNEL, RXADDRESS, PACKET_LENGTH); m_wii_open(); // and open wii camera sei(); // enable global interrups set(DDRC,7); set(DDRB,7); int position[3]; // array for robot position int x_curr; // current x position int y_curr; // current y position int theta_curr; // current angle int i; int a; // x, y and theta values int x_pos[11]; int y_pos[11]; int theta[11]; char send[10]; int side; int x1; // calculate initial positions int status; // int x; // int y; // int theta1; int hasPuck = 0; // main LOOP while(1) { if (flag) { m_rf_read(buffer1, PACKET_LENGTH); testing = (unsigned char)buffer1[0]; a = state(testing); // m_rf_read(buffer, PACKET_LENGTH); // x = (unsigned char)buffer[0]; // y = (unsigned char)buffer[1]; // theta1 = (unsigned char)buffer[2]; if (flag1){ for(i = 0; i<10; i++) { current_location(position); x1 = position[0]; } // figure out what side robot starts on if (x1 > 0) { side = -1; } else { side = 1; } } flag = 0; } // m_rf_open(CHANNEL, RXADDRESS, PACKET_LENGTH); // store 10 most recent position readings for (i=0; i < 11; i++) { current_location(position); x_pos[i] = position[0]; y_pos[i] = position[1]; theta[i] = position[2]; } // filter position filter(x_pos,y_pos,theta); // current position x_curr = x_pos[11]; y_curr = y_pos[11]; theta_curr = theta[11]; if (x_curr > 0) { m_red(ON); } else if (x_curr<0) { m_red(OFF); } if (y_curr > 0) { m_green(ON); } else if (y_curr<0) { m_green(OFF); } // send[0] = x_curr;//(char) x_curr; // send[1] = y_curr;//(char) y_curr; // send[2] = theta_curr;//(char) theta_curr; // status = m_rf_send(TXaddress, send, PACKET_LENGTH); // if (status){m_red(TOGGLE)}; // m_usb_tx_string("X Pos: "); // m_usb_tx_int(x); // m_usb_tx_string(" "); // m_usb_tx_string("Y POSITION: "); // m_usb_tx_int(y); // m_usb_tx_string(" "); // m_usb_tx_string("ANGLE: "); // m_usb_tx_int(theta1); // m_usb_tx_string(" "); // m_usb_tx_string("\n"); a = 2; // COMM TEST if (a == 1) { // ADD CODE // m_red(ON); if (side == 1) { set(PORTC,7); } else { set(PORTB,7); } } // PLAY GAME else if (a == 2) { // m_red(OFF); //int hasPuck = follow_puck(); //hasPuck = 1; // goalie(x_curr, y_curr, theta_curr, side); if(hasPuck) { //score_goal(x_curr, y_curr, theta_curr, side); //turn_robot(0,0,0,0); } } // GOAL R else if (a == 3) { //side = 1; //m_green(TOGGLE); } // GOAL B else if ( a == 4) { //side = -1; //m_green(TOGGLE); } else if(a == 5) { turn_robot(0,0,0,0); // m_red(ON); } // PAUSE, HALF TIME, GAME OVER if (a == 6 || a == 7) { // STOP ROBOT turn_robot(0,0,0,0); m_red(ON); } else {} // // COMM PROTOCOL INSTRUCTIONS // m_usb_tx_string("STATE: "); // m_usb_tx_int(a); // m_usb_tx_string(" "); // m_usb_tx_string("FLAG: "); // m_usb_tx_int(flag); // m_usb_tx_string(" "); // m_usb_tx_string("TESTING: "); // m_usb_tx_int(testing); // m_usb_tx_string(" "); // m_usb_tx_string("\n"); } }