void handleFrameExit() { if (hasExited()) return; // Call the getters for their side-effects of caching the result: back(this, NULL); code(this, NULL); globals(this, NULL); assert(!_locals); _locals = incref(locals(this, NULL)); ASSERT(frame_info->stmt->lineno > 0 && frame_info->stmt->lineno < 1000000, "%d", frame_info->stmt->lineno); _linenumber = frame_info->stmt->lineno; frame_info = NULL; // this means exited == true assert(hasExited()); }
static BORROWED(Box*) locals(Box* obj, void*) noexcept { auto f = static_cast<BoxedFrame*>(obj); if (f->hasExited()) return f->_locals; return f->frame_info->updateBoxedLocals(); }
static Box* lineno(Box* obj, void*) noexcept { auto f = static_cast<BoxedFrame*>(obj); if (f->hasExited()) { ASSERT(f->_linenumber > 0 && f->_linenumber < 1000000, "%d", f->_linenumber); return boxInt(f->_linenumber); } AST_stmt* stmt = f->frame_info->stmt; ASSERT(stmt->lineno > 0 && stmt->lineno < 1000000, "%d", stmt->lineno); return boxInt(stmt->lineno); }
/* processMoves(void) reads movement commands, processing each command, in turn to move the corresponding car within the carpark. Each movement command is constrained to ensure the corresponding car does not collide with any other car and that the car remains within the bounds of the carpark. A movement command is performed (and the carpark updated to reflect the movement) if the corresponding car can move in the given direction. At the completion of each movement command (regardless of whether the command lead to actual movement), the current state of the carpark is printed. The function completes immediately if a movement command leads to the target car exiting. The function terminates the program if any command is invalid. */ static void processMoves(void) { char line[BUFSIZ]; char car; char direction; int amount; DIRECTION d; int i = 0; while(!hasExited()) // make sure the TARGETCAR is not at the exit location { printPrompt(); // prompt the user for a move fgets(line, sizeof line, stdin); trimLine(line); sscanf(line, "%c %c %d", &car, &direction, &amount); // assign the users move to appropiate variables if(!isValidCarparkEntry(car)) // check the car is defined in the carpark { fprintf(stderr, "Fatal Error: car %c was not found in the grid\n", car); exit(EXIT_FAILURE); } /* The following code sets the enum value from the user input */ if(direction == 'N' || direction == 'n') { d = NORTH; } else if(direction == 'S' || direction == 's') { d = SOUTH; } else if(direction == 'E' || direction == 'e') { d = EAST; } else if(direction == 'W' || direction == 'w') { d = WEST; } moveCar(car, d, amount); i = moveCar(car, d, amount); printf("Processed move: %c %c %d\n", car, direction, amount); printCarpark(); } printf("The target car is now free after %d moves!\n", i); }
int Process:: condWait(int) { return hasExited(); }