void processCondition(SymbolTable *table, Node *ptr) { if (ptr->noderep == NONTERM) { processOperator(table, ptr); } else { rv_emit(table, ptr); } }
//-------------------------------------------< Operator Control >--------------------------------------------\\ task usercontrol() { while (!bIfiAutonomousMode) { getInput(); processOperator(); doOutput(); } }
void QueryManager::processRebuildWorkOrderCompleteMessage(const dag_node_index op_index) { query_exec_state_->decrementNumRebuildWorkOrders(op_index); if (checkRebuildOver(op_index)) { markOperatorFinished(op_index); for (const pair<dag_node_index, bool> &dependent_link : query_dag_->getDependents(op_index)) { const dag_node_index dependent_op_index = dependent_link.first; if (checkAllBlockingDependenciesMet(dependent_op_index)) { processOperator(dependent_op_index, true); } } } }
task usercontrol() { initializeOperator(); StartTask(UpdatePIDControllers); #ifdef _SIMULATED while (!bSimulatedAutonomousMode) #else while (!bIfiAutonomousMode) #endif { getInput(); processOperator(); if (EnableOutput) doOutput(); } }
task main() { initialize(); while(1) { input(); switch (sysCurrentMode) { case AUTONOMOUS: processAutonomous(); break; case OPERATOR: processOperator(); break; case DISABLED: zeroMotors(); break; } output(); LCD(); nextLoopIteration(); } }
int processInput(Drawing d, FILE *input) { double value = 0; int res = 0; char string[100]; while (fscanf(input, " %s", string) != EOF) { if (sscanf(string, " %lf", &value)) { res = stack_push(d->stack, value); } else { res = processOperator(d, string); } if (res != PROCESSOR_SUCCESS && res != 1) return res; } return PROCESSOR_SUCCESS; }
void Foreman::processOperator(RelationalOperator *op, dag_node_index index, bool recursively_check_dependents) { if (fetchNormalWorkOrders(op, index)) { // Fetched work orders. Return to wait for the generated work orders to // execute, and skip the execution-finished checks. return; } if (checkNormalExecutionOver(index)) { if (checkRebuildRequired(index)) { if (!checkRebuildInitiated(index)) { // Rebuild hasn't started, initiate it. if (initiateRebuild(index)) { // Rebuild initiated and completed right away. markOperatorFinished(index); } else { // Rebuild WorkOrders have been generated. return; } } else if (checkRebuildOver(index)) { // Rebuild had been initiated and it is over. markOperatorFinished(index); } } else { // Rebuild is not required and normal execution over, mark finished. markOperatorFinished(index); } // If we reach here, that means the operator has been marked as finished. if (recursively_check_dependents) { for (pair<dag_node_index, bool> dependent_link : query_dag_->getDependents(index)) { if (checkAllBlockingDependenciesMet(dependent_link.first)) { processOperator( query_dag_->getNodePayloadMutable(dependent_link.first), dependent_link.first, true); } } } } }
void Foreman::initialize() { if (cpu_id_ >= 0) { // We can pin the foreman thread to a CPU if specified. ThreadUtil::BindToCPU(cpu_id_); } DEBUG_ASSERT(query_dag_ != nullptr); initializeState(); // Collect all the workorders from all the relational operators in the DAG. const dag_node_index dag_size = query_dag_->size(); for (dag_node_index index = 0; index < dag_size; ++index) { if (checkAllBlockingDependenciesMet(index)) { query_dag_->getNodePayloadMutable(index)->informAllBlockingDependenciesMet(); processOperator(index, false); } } // Dispatch the WorkOrders generated so far. dispatchWorkerMessages(0, 0); }
void QueryManager::processWorkOrderCompleteMessage( const dag_node_index op_index) { query_exec_state_->decrementNumQueuedWorkOrders(op_index); // Check if new work orders are available and fetch them if so. fetchNormalWorkOrders(op_index); if (checkRebuildRequired(op_index)) { if (checkNormalExecutionOver(op_index)) { if (!checkRebuildInitiated(op_index)) { if (initiateRebuild(op_index)) { // Rebuild initiated and completed right away. markOperatorFinished(op_index); } else { // Rebuild under progress. } } else if (checkRebuildOver(op_index)) { // Rebuild was under progress and now it is over. markOperatorFinished(op_index); } } else { // Normal execution under progress for this operator. } } else if (checkOperatorExecutionOver(op_index)) { // Rebuild not required for this operator and its normal execution is // complete. markOperatorFinished(op_index); } for (const pair<dag_node_index, bool> &dependent_link : query_dag_->getDependents(op_index)) { const dag_node_index dependent_op_index = dependent_link.first; if (checkAllBlockingDependenciesMet(dependent_op_index)) { // Process the dependent operator (of the operator whose WorkOrder // was just executed) for which all the dependencies have been met. processOperator(dependent_op_index, true); } } }
TokenStatus Translator::getExpression(Token *&token, DataType dataType, int level) { TokenStatus status; DataType expectedDataType = dataType; forever { if (token == NULL && (status = getToken(token, expectedDataType)) != Good_TokenStatus) { break; } if (token->isCode(OpenParen_Code)) { // push open parentheses onto hold stack to block waiting tokens // during the processing of the expression inside the parentheses m_holdStack.push(token); // get an expression and terminating token token = NULL; if (expectedDataType == None_DataType) { expectedDataType = Any_DataType; } if ((status = getExpression(token, expectedDataType, level + 1)) != Done_TokenStatus) { if (m_table.isUnaryOperator(token)) { status = ExpBinOpOrParen_TokenStatus; } if (status == Parser_TokenStatus && token->isDataType(None_DataType)) { status = ExpOpOrParen_TokenStatus; } break; // exit on error } // check terminating token if (!token->isCode(CloseParen_Code)) { status = ExpOpOrParen_TokenStatus; break; } // make sure holding stack contains the open parentheses Token *topToken = m_holdStack.pop().token; if (!topToken->code() == OpenParen_Code) { // oops, no open parentheses (this should not happen) return BUG_UnexpectedCloseParen; } // replace first and last operands of token on done stack m_doneStack.replaceTopFirstLast(topToken, token); // mark close paren as used for last operand and pending paren // (so it doesn't get deleted until it's not used anymore) token->addSubCode(Last_SubCode + Used_SubCode); // set highest precedence if not an operator on done stack top // (no operators in the parentheses) topToken = m_doneStack.top().rpnItem->token(); m_lastPrecedence = topToken->isType(Operator_TokenType) ? m_table.precedence(topToken) : HighestPrecedence; // set pending parentheses token pointer m_pendingParen = token; token = NULL; // get another token } else { Code unaryCode; if ((unaryCode = m_table.unaryCode(token)) != Null_Code) { token->setCode(unaryCode); // change token to unary operator } // get operand else if ((status = getOperand(token, expectedDataType)) != Good_TokenStatus) { break; } else if (doneStackTopToken()->isDataType(None_DataType) && dataType != None_DataType) { // print functions are not allowed token = doneStackPopErrorToken(); status = expectedErrStatus(dataType); break; } else { token = NULL; // get another token } } if (token == NULL) { // get binary operator or end-of-expression token if ((status = getToken(token)) != Good_TokenStatus) { // if parser error then caller needs to handle it break; } if (doneStackTopToken()->isDataType(None_DataType) && m_holdStack.top().token->isNull() && dataType == None_DataType) { // for print functions return now with token as terminator status = Done_TokenStatus; break; } // check for unary operator (token should be a binary operator) if (m_table.isUnaryOperator(token)) { status = ExpBinOpOrEnd_TokenStatus; break; } } // check for and process operator (unary or binary) status = processOperator(token); if (status == Done_TokenStatus) { if (level == 0) { // add convert code if needed or report error Token *doneToken = m_doneStack.top().rpnItem->token(); Code cvt_code = m_table.cvtCode(doneToken, dataType); if (cvt_code == Invalid_Code) { delete token; // delete terminating token token = doneStackPopErrorToken(); status = expectedErrStatus(dataType); } else if (cvt_code != Null_Code) { if (doneToken->isType(Constant_TokenType)) { // constants don't need conversion if (dataType == Integer_DataType && doneToken->isDataType(Double_DataType)) { delete token; // delete terminating token token = doneStackPopErrorToken(); status = ExpIntConst_TokenStatus; } } else // append hidden conversion code { m_output->append(m_table.newToken(cvt_code)); } } } break; } else if (status != Good_TokenStatus) { break; } // get operator's expected data type, reset token and loop back expectedDataType = m_table.expectedDataType(token); token = NULL; } return status; }
Value *ValueProcessor::processOperation(TokenList::const_iterator &i, TokenList::const_iterator &end, const Value &operand1, const ValueScope &scope, ValueProcessor::Operator lastop, bool defaultVal) const { TokenList::const_iterator tmp; const Value *operand2; Value *result; Operator op; const Token *opToken; if (i == end) return NULL; opToken = &(*i); tmp = i; if ((op = processOperator(tmp, end)) == OP_NONE || (lastop != OP_NONE && lastop >= op)) return NULL; i = tmp; skipWhitespace(i, end); operand2 = processConstant(i, end, scope, defaultVal); if (operand2 == NULL) { if (i == end) throw new ParseException("end of line", "Constant or @-variable", opToken->line, opToken->column, opToken->source); else throw new ParseException( *i, "Constant or @-variable", (*i).line, (*i).column, (*i).source); } skipWhitespace(i, end); while ((result = processOperation(i, end, *operand2, scope, op, defaultVal))) { delete operand2; operand2 = result; skipWhitespace(i, end); } if (op == OP_ADD) result = operand1 + *operand2; else if (op == OP_SUBSTRACT) result = operand1 - *operand2; else if (op == OP_MULTIPLY) result = operand1 * *operand2; else if (op == OP_DIVIDE) result = operand1 / *operand2; else if (op == OP_EQUALS) result = new BooleanValue(operand1 == *operand2); else if (op == OP_LESS) result = new BooleanValue(operand1 < *operand2); else if (op == OP_GREATER) result = new BooleanValue(operand1 > *operand2); else if (op == OP_LESS_EQUALS) result = new BooleanValue(operand1 <= *operand2); else if (op == OP_GREATER_EQUALS) result = new BooleanValue(operand1 >= *operand2); delete operand2; result->setLocation(*opToken); return result; }
int checkPredefined(SymbolTable *table, Node *ptr) { Node *p=ptr; char *functionName; int noArguments; int stIndex; functionName = p->token.tokenValue; if (strcmp(functionName, "read") == 0) { noArguments = 1; emit0("ldp"); p = p->next->son; while (p) { if (p->noderep == NONTERM) { processOperator(table, p); } else { stIndex = lookup(table, p->token.tokenValue); if (stIndex == -1) { return 0; } emit2("lda", table->rows[stIndex].base, table->rows[stIndex].offset); } noArguments--; p = p->next; } if (noArguments > 0) { fprintf(file, "%s: too few actual arguments\n", functionName); } if (noArguments < 0) { fprintf(file, "%s: too many actual arguments\n", functionName); } emitJump("call", functionName); return 1; } else if (strcmp(functionName, "write") == 0) { noArguments = 1; emit0("ldp"); p = p->next->son; while (p) { if (p->noderep == NONTERM) { processOperator(table, p); } else { stIndex = lookup(table, p->token.tokenValue); if (stIndex == -1) return 0; emit2("lod", table->rows[stIndex].base, table->rows[stIndex].offset); } noArguments--; p=p->next; } if (noArguments > 0) { fprintf(file, "%s: too few actual arguments\n", functionName); } if (noArguments < 0) { fprintf(file, "%s: too many actual arguments\n", functionName); } emitJump("call", functionName); return 1; } else if (strcmp(functionName, "lf") == 0) { emitJump("call", functionName); return 1; } return 0; }
void processOperator(SymbolTable *table, Node *ptr) { int stIndex; switch(ptr->token.tokenNumber) { case ASSIGN_OP: { Node *lhs = ptr->son, *rhs = ptr->son->next; if (lhs->noderep == NONTERM) { lvalue = 1; processOperator(table, lhs); lvalue = 0; } if (rhs->noderep == NONTERM) { processOperator(table, rhs); } else { rv_emit(table, rhs); } if (lhs->noderep == TERMINAL) { stIndex = lookup(table, lhs->token.tokenValue); if (stIndex == -1) { fprintf(stderr, "undefined variable: %s\n", lhs->token.tokenValue); return; } emit2("str", table->rows[stIndex].base, table->rows[stIndex].offset); } else { emit0("sti"); } break; } case ADD_ASSIGN: case SUB_ASSIGN: case MUL_ASSIGN: case DIV_ASSIGN: case MOD_ASSIGN: { Node *lhs = ptr->son, *rhs = ptr->son->next; int nodeNumber = ptr->token.tokenNumber; ptr->token.tokenNumber = ASSIGN_OP; if (lhs->noderep == NONTERM) { lvalue = 1; processOperator(table, lhs); lvalue = 0; } ptr->token.tokenNumber = nodeNumber; if (lhs->noderep == NONTERM) { processOperator(table, lhs); } else { rv_emit(table, lhs); } if (rhs->noderep == NONTERM) { processOperator(table, rhs); } else { rv_emit(table, rhs); } switch(ptr->token.tokenNumber) { case ADD_ASSIGN: emit0("add"); break; case SUB_ASSIGN: emit0("sub"); break; case MUL_ASSIGN: emit0("mult"); break; case DIV_ASSIGN: emit0("div"); break; case MOD_ASSIGN: emit0("mod"); break; } if (lhs->noderep == TERMINAL) { stIndex = lookup(table, lhs->token.tokenValue); if (stIndex == -1) { fprintf(file, "undefined variable: %s\n", lhs->son->token.tokenValue); return; } emit2("str", table->rows[stIndex].base, table->rows[stIndex].offset); } else { emit0("sti"); } break; } case ADD: case SUB: case MUL: case DIV: case MOD: case EQ: case NE: case GT: case LT: case GE: case LE: case LOGICAL_AND: case LOGICAL_OR: { Node *lhs = ptr->son, *rhs = ptr->son->next; if (lhs->noderep == NONTERM) { processOperator(table, lhs); } else { rv_emit(table, lhs); } if (rhs->noderep == NONTERM) { processOperator(table, rhs); } else { rv_emit(table, rhs); } switch(ptr->token.tokenNumber) { case ADD: emit0("add"); break; case SUB: emit0("sub"); break; case MUL: emit0("mult"); break; case DIV: emit0("div"); break; case MOD: emit0("mod"); break; case EQ: emit0("eq"); break; case NE: emit0("ne"); break; case GT: emit0("gt"); break; case LT: emit0("lt"); break; case GE: emit0("ge"); break; case LE: emit0("le"); break; case LOGICAL_AND: emit0("and"); break; case LOGICAL_OR: emit0("or"); break; } break; } case UNARY_MINUS: case LOGICAL_NOT: { Node *p = ptr->son; if (p->noderep == NONTERM) { processOperator(table, p); } else { rv_emit(table, p); } switch(ptr->token.tokenNumber) { case UNARY_MINUS: emit0("neg"); break; case LOGICAL_NOT: emit0("not"); break; } break; } case INDEX: { Node *indexExp = ptr->son->next; if (indexExp->noderep == NONTERM) processOperator(table, indexExp); else rv_emit(table, indexExp); stIndex = lookup(table, ptr->son->token.tokenValue); if (stIndex == -1) { fprintf(file, "undefined variable: %s\n", ptr->son->token.tokenValue); return; } emit2("lda", table->rows[stIndex].base, table->rows[stIndex].offset); emit0("add"); if (!lvalue) { emit0("ldi"); } break; } case PRE_INC: case PRE_DEC: case POST_INC: case POST_DEC: { Node *p = ptr->son; Node *q; int stIndex; int amount = 1; if (p->noderep == NONTERM) { processOperator(table, p); } else { rv_emit(table, p); } q = p; while (q->noderep != TERMINAL) { q = q->son; } if (!q || (q->token.tokenNumber != IDENT)) { fprintf(file, "increment/decrement operators can not be applied in expression\n"); return; } stIndex = lookup(table, q->token.tokenValue); if (stIndex == -1) { return; } switch(ptr->token.tokenNumber) { case PRE_INC: emit0("inc"); break; case PRE_DEC: emit0("dec"); break; case POST_INC: emit0("inc"); break; case POST_DEC: emit0("dec"); break; } if (p->noderep == TERMINAL) { stIndex = lookup(table, p->token.tokenValue); if (stIndex == -1) { return; } emit2("str", table->rows[stIndex].base, table->rows[stIndex].offset); } else if (p->token.tokenNumber == INDEX) { lvalue = 1; processOperator(table, p); lvalue = 0; emit0("swp"); emit0("sti"); } else fprintf(file, "error in increment/decrement operators\n"); break; } case CALL: { Node *p = ptr->son; char *functionName; int stIndex; int noArguments; if (checkPredefined(table, p)) { break; } functionName = p->token.tokenValue; stIndex = lookup(rootTable, functionName); if (stIndex == -1) { fprintf(file, "%s: undefined function\n", functionName); break; } noArguments = rootTable->rows[stIndex].width; emit0("ldp"); p = p->next->son; while (p) { if (p->noderep == NONTERM) { processOperator(table, p); } else { rv_emit(table, p); } noArguments--; p = p->next; } if (noArguments > 0) { fprintf(file, "%s: too few actual arguments\n", functionName); } if (noArguments < 0) { fprintf(file, "%s: too many actual arguments\n", functionName); } emitJump("call", ptr->son->token.tokenValue); break; } } }
/* FIXME: Define the type 'struct command_stream' here. This should complete the incomplete type declaration in command.h. */ command_stream_t make_command_stream(int(*get_next_byte) (void *), void *get_next_byte_argument) { /* FIXME: Replace this with your implementation. You may need to add auxiliary functions and otherwise modify the source code. You can also use external functions defined in the GNU C Library. */ if (DEBUG) printf("291 Begin make_command_stream\n"); initStream(); size_t sizeofBuffer = 1024; char* buffer = (char*)checked_malloc(sizeofBuffer); char curr; size_t filled = 0; while ((curr = get_next_byte(get_next_byte_argument)) != EOF) { buffer[filled] = curr; filled++; if (filled == sizeofBuffer) { sizeofBuffer *= 2; buffer = (char*)checked_grow_alloc(buffer, &sizeofBuffer); } } //***For the parser: //Word int bufferWordSize = 10; int currWord = 0; //char ** wordElement; char** wordElement = checked_malloc(sizeof(char*)); wordElement[currWord] = (char*)checked_malloc(bufferWordSize); int usedWord = 0; //Input int bufferInputSize = 10; char* inputElement = (char*)checked_malloc(bufferInputSize); int usedInput = 0; //Output int bufferOutputSize = 10; char* outputElement = (char*)checked_malloc(bufferOutputSize); int usedOutput = 0; //***Initialize operator and command stacks initStacks(); if (DEBUG) printf("333 Buffer created, initStacks()\n"); int i = 0; while (i < (int)filled) { if (DEBUG) printf("on buffer %d\n", i); //***When you want to add a character*************************// int op = -1; int openCount = 0; int closedCount = 0; if (buffer[i] == '`') error(1, 0, "Line %d: %c", __LINE__, buffer[i]); if (buffer[i] == '(') { openCount = 1; closedCount = 0; int x = i; while (x < (int) filled) { x++; if (buffer[x] == '(') openCount++; if (buffer[x] == ')') closedCount++; if (closedCount == openCount) break; } if (closedCount != openCount) error(1, 0, "Line %d: Expected ')' for end of subshell", __LINE__); } if(buffer[i] == ')') { if(openCount == 0) error(1, 0, "Line %d: Expected '(' before ')'", __LINE__); } if(buffer[i] = '(') { op = numberOfOper(&buffer[i]); processOperator(op); } //Case of ' ' while (buffer[i] == ' ' && usedWord == 0) i++; if (buffer[i] == ' ' && usedWord != 0) { if (usedWord >= bufferWordSize) { bufferWordSize += 10; wordElement[currWord] = (char*)checked_realloc(wordElement[currWord], bufferWordSize); } //i++; wordElement[currWord][usedWord] = '\0'; while (buffer[i + 1] == ' ') i++; usedWord = 0; bufferWordSize = 10; currWord++; wordElement[currWord] = (char*)checked_malloc(bufferWordSize); //wordElement[currWord][usedWord] = buffer[i]; //usedWord++; } //Case of carrots //WHAT IF a<b>c>d<a....?! You're making a simple command out of a<b>c which then // must also be the word of >d<a //Case of '<' first else if (buffer[i] == '<') { int k = i; while (buffer[k-1] == ' ') { k--; if(buffer[k-1] == '\n') error(1, 0, "Line %d: Operator and word on diff lines", __LINE__); } if (wordElement[0][0] == '\0') error(1, 0, "Line %d: No command given to '<'", __LINE__); i++; while (buffer[i] != '<' && buffer[i] != '>' && buffer[i] != '&' && buffer[i] != '|' && buffer[i] != '(' && buffer[i] != ')' && buffer[i] != ';' && buffer[i] != '\n') { if (i == filled) { if (DEBUG) printf("378 Complete command, free buffer bc EOF\n"); currWord++; wordElement[currWord] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; makeSimpleCommand(wordElement, inputElement, outputElement); completeCommand(); //free(buffer); return headStream; } if (buffer[i] == ' ') i++; else { if (usedInput >= bufferInputSize) { bufferInputSize += 10; inputElement = (char*)checked_realloc(inputElement, bufferInputSize); } inputElement[usedInput] = buffer[i]; usedInput++; i++; } } if (usedInput >= bufferInputSize) { bufferInputSize += 10; inputElement = (char*)checked_realloc(inputElement, bufferInputSize); } if (usedInput == 0) error(1, 0, "Line %d: No input after '<'", __LINE__); inputElement[usedInput] = '\0'; usedInput++; if (buffer[i] == '>') { i++; while (buffer[i] != '<' && buffer[i] != '>' && buffer[i] != '&' && buffer[i] != '|' && buffer[i] != '(' && buffer[i] != ')' && buffer[i] != ';' && buffer[i] != '\n') { if (i == filled) { if (DEBUG) printf("413 Complete command, free buffer at EOF\n"); currWord++; wordElement[currWord] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; makeSimpleCommand(wordElement, inputElement, outputElement); completeCommand(); //free(buffer); return headStream; } if (buffer[i] == ' ') i++; else { if (usedOutput >= bufferOutputSize) { bufferOutputSize += 10; outputElement = (char*)checked_realloc(outputElement, bufferOutputSize); } outputElement[usedOutput] = buffer[i]; usedOutput++; i++; } } if (usedOutput >= bufferOutputSize) { bufferOutputSize += 10; outputElement = (char*)checked_realloc(outputElement, bufferOutputSize); } if (usedOutput == 0) error(1, 0, "Line %d: No input after '<'", __LINE__); outputElement[usedOutput] = '\0'; usedOutput++; //i--; //Check logic } i--; } /////CHECK FOR EXTRA i++!!!!! //Case of '>' first else if (buffer[i] == '>') { int k = i; while (buffer[k-1] == ' ') { k--; if(buffer[k-1] == '\n') error(1, 0, "Line %d: Operator and word on diff lines", __LINE__); } if (wordElement[0][0] == '\0') error(1, 0, "Line %d: No command given to '<'", __LINE__); i++; while (buffer[i] != '<' && buffer[i] != '>' && buffer[i] != '&' && buffer[i] != '|' && buffer[i] != '(' && buffer[i] != ')' && buffer[i] != ';' && buffer[i] != '\n') { if (i == filled) { if (DEBUG) printf("471 Complete Command, free buffer at EOF"); currWord++; wordElement[currWord] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; makeSimpleCommand(wordElement, inputElement, outputElement); completeCommand(); //free(buffer); return headStream; } if (buffer[i] == ' ') i++; else { if (usedOutput >= bufferOutputSize) { bufferOutputSize += 10; outputElement = (char*)checked_realloc(outputElement, bufferOutputSize); } outputElement[usedOutput] = buffer[i]; usedOutput++; i++; } } if (usedOutput >= bufferOutputSize) { bufferOutputSize += 10; outputElement = (char*)checked_realloc(outputElement, bufferOutputSize); } if (usedOutput == 0) error(1, 0, "Line %d: No input after '<'", __LINE__); outputElement[usedOutput] = '\0'; usedOutput++; if (buffer[i] == '<') { i++; while (buffer[i] != '<' && buffer[i] != '>' && buffer[i] != '&' && buffer[i] != '|' && buffer[i] != '(' && buffer[i] != ')' && buffer[i] != ';' && buffer[i] != '\n') { if (i == filled) { if (DEBUG) printf("505 Complete Command, free buffer at EOF"); currWord++; wordElement[currWord] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; makeSimpleCommand(wordElement, inputElement, outputElement); completeCommand(); //free(buffer); return headStream; } if (buffer[i] == ' ') i++; else { if (usedInput >= bufferInputSize) { bufferInputSize += 10; inputElement = (char*)checked_realloc(inputElement, bufferInputSize); } inputElement[usedInput] = buffer[i]; usedInput++; i++; } } if (usedInput >= bufferInputSize) { bufferInputSize += 10; inputElement = (char*)checked_realloc(inputElement, bufferInputSize); } if (usedInput == 0) error(1, 0, "Line %d: No input after '<'", __LINE__); inputElement[usedInput] = '\0'; usedInput++; } wordElement[currWord + 1] = '\0'; /*if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; if(DEBUG) printf("makeSimpleCommand %s\n", wordElement[0]); makeSimpleCommand(wordElement, inputElement, outputElement); bufferWordSize = 10; currWord = 0; usedWord = 0; usedInput = 0; usedOutput = 0; wordElement = (char**)checked_malloc(sizeof(char*)); wordElement[currWord] = (char*)checked_malloc(bufferWordSize); inputElement = (char*)checked_malloc(bufferInputSize); outputElement = (char*)checked_malloc(bufferOutputSize);*/ i--; } //Operators //After every operator is encountered, use makeSimpleCommand to push the command on the stack //Case of '|' else if (buffer[i] == '|') { int k = i; while (buffer[k-1] == ' ') { k--; if(buffer[k-1] == '\n') error(1, 0, "Line %d: Operator and word on diff lines", __LINE__); } if (buffer[i+1] == '|' && operatorStack == NULL) error(1, 0, "Line %d: Missing pipe for '||'", __LINE__); if (wordElement[0][0] == '\0') error(1, 0, "Line %d: Nothing for '|'", __LINE__); //if (commandStack == NULL) // error(1, 0, "Line %d: Nothing to run '|' on"); if (buffer[i + 1] == '|' && buffer[i+2] == '|') error(1, 0, "Line %d: Invalid Command, too many '|'", i); op = numberOfOper(&buffer[i]); //error(1, 0, "Line %d: Nothing to pipe", __LINE__); if (buffer[i-1] != ' ') currWord++; wordElement[currWord] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; if (DEBUG) printf(" 566 makeSimpleCommand %s\n", wordElement[0]); makeSimpleCommand(wordElement, inputElement, outputElement); bufferWordSize = 10; currWord = 0; usedWord = 0; usedInput = 0; usedOutput = 0; wordElement = (char**)checked_malloc(sizeof(char*)); wordElement[currWord] = (char*)checked_malloc(bufferWordSize); inputElement = (char*)checked_malloc(bufferInputSize); outputElement = (char*)checked_malloc(bufferOutputSize); if (DEBUG) printf("577 Process operator %d\n", op); processOperator(op); if (op == 3) i++; if (buffer[i + 1] == ' ') i++; //i++; } //Case of '&' else if (buffer[i] == '&') { int k = i; while (buffer[k-1] == ' ') { k--; if(buffer[k-1] == '\n') error(1, 0, "Line %d: Operator and word on diff lines", __LINE__); } //if (buffer[i] == '&' && operatorStack == NULL) // error(1, 0, "Line %d: Missing pipe for '&&'", __LINE__); if (wordElement[0][0] == '\0') error(1, 0, "Line %d: Nothing for '|'", __LINE__); if (buffer[i + 1] == '&' && buffer[i+2] == '&') error(1, 0, "Line %d: Invalid Command, too many '&'", i); op = numberOfOper(&buffer[i]); if (buffer[i-1] != ' ') currWord++; wordElement[currWord] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; if (DEBUG) printf("592 makeSimpleCommand %s\n", wordElement[0]); makeSimpleCommand(wordElement, inputElement, outputElement); bufferWordSize = 10; usedWord = 0; currWord = 0; usedInput = 0; usedOutput = 0; wordElement = (char**)checked_malloc(sizeof(char*)); wordElement[currWord] = (char*)checked_malloc(bufferWordSize); inputElement = (char*)checked_malloc(bufferInputSize); outputElement = (char*)checked_malloc(bufferOutputSize); processOperator(op); i++; if (buffer[i + 1] == ' ') i++; } //Case of ';' else if (buffer[i] == ';') { int k = i; while (buffer[k-1] == ' ') { k--; if(buffer[k-1] == '\n') error(1, 0, "Line %d: Operator and word on diff lines", __LINE__); } if(wordElement[0][0] == '\0') error(1, 0, "Line %d: Nothing before sequence", i); op = numberOfOper(&buffer[i]); currWord++; wordElement[currWord] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; if (DEBUG) printf("617 makeSimpleCommand %s\n", wordElement[0]); if ((currWord = 0) || (currWord == 1)) error(1, 0, "Line %d: Nothing to run ';' on", i); makeSimpleCommand(wordElement, inputElement, outputElement); bufferWordSize = 10; usedWord = 0; currWord = 0; usedInput = 0; usedOutput = 0; wordElement = (char**)checked_malloc(sizeof(char*)); wordElement[currWord] = (char*)checked_malloc(bufferWordSize); inputElement = (char*)checked_malloc(bufferInputSize); outputElement = (char*)checked_malloc(bufferOutputSize); processOperator(op); //i++; } //Case of '\n' else if (buffer[i] == '\n' && i != 0) { /*int scChecker = i; while (buffer[i + 1] == ' ') { scChecker++; if (buffer[scChecker + 1] == ';') error(1, 0, "Line %d: Newline followed by ';'"); }*/ if (buffer[i+1] == ';') error(1, 0, "Line %d: Newline followed by ';'", i); if ((i + 1) == (int)filled) { currWord++; wordElement[currWord] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; if (DEBUG) printf("654 makeSimpleCommand %s\n", wordElement[0]); makeSimpleCommand(wordElement, inputElement, outputElement); bufferWordSize = 10; currWord = 0; usedWord = 0; usedInput = 0; usedOutput = 0; wordElement = (char**)checked_malloc(sizeof(char*)); wordElement[currWord] = (char*)checked_malloc(bufferWordSize); inputElement = (char*)checked_malloc(bufferInputSize); outputElement = (char*)checked_malloc(bufferOutputSize); completeCommand(); free(buffer); return headStream; } char lastC; int back = 1; while (buffer[i - back] == ' ' && i - back >= 0) { //lastC = buffer[i - back]; back++; } lastC = buffer[i - back]; if (buffer[i + 1] == '\n') { while (buffer[i + 1] == '\n') i++; if (lastC != '|' && lastC != '&') { currWord++; wordElement[currWord] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; if (DEBUG) printf("654 makeSimpleCommand %s\n", wordElement[0]); makeSimpleCommand(wordElement, inputElement, outputElement); bufferWordSize = 10; currWord = 0; usedWord = 0; usedInput = 0; usedOutput = 0; wordElement = (char**)checked_malloc(sizeof(char*)); wordElement[currWord] = (char*)checked_malloc(bufferWordSize); inputElement = (char*)checked_malloc(bufferInputSize); outputElement = (char*)checked_malloc(bufferOutputSize); completeCommand(); } } else { if (lastC == '|' || lastC == '&' || lastC == '<' || lastC || '>') { while (buffer[i + 1] == '\n') i++;//////SPIT ERROR? } else { char swap = ';'; op = numberOfOper(&swap); wordElement[currWord + 1] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; if (DEBUG) printf(" 679 makeSimpleCommand %s\n", wordElement[0]); makeSimpleCommand(wordElement, inputElement, outputElement); bufferWordSize = 10; currWord = 0; usedWord = 0; usedInput = 0; usedOutput = 0; wordElement = (char**)checked_malloc(sizeof(char*)); wordElement[currWord] = (char*)checked_malloc(bufferWordSize); inputElement = (char*)checked_malloc(bufferInputSize); outputElement = (char*)checked_malloc(bufferOutputSize); processOperator(op); } } } //Case of # (comment) else if (buffer[i] == '#') { if (DEBUG) printf("698 Got a comment!\n"); while (buffer[i] != '\n') i++; } //Else else { if (buffer[i] == '\'') { if (buffer[i + 1] == 'E' && buffer[i + 2] == 'O' && buffer[i + 3] == 'F') break; } //if (buffer[i] != ' ') wordElement[currWord][usedWord] = buffer[i]; usedWord++; if (i + 1 == filled) { currWord++; wordElement[currWord] = '\0'; if (usedInput == 0) inputElement = NULL; if (usedOutput == 0) outputElement = NULL; makeSimpleCommand(wordElement, inputElement, outputElement); completeCommand(); } } i++; } free(buffer); return headStream; }
// TODO(harshad) - There is duplication in terms of functionality provided by // TMB and ForemanMessage class with respect to determining the message types. // Try to use TMB message types for infering the messsage types consistently. bool Foreman::processMessage(const ForemanMessage &message) { const dag_node_index dag_size = query_dag_->size(); // Get the relational operator that caused this message to be sent. dag_node_index response_op_index = message.getRelationalOpIndex(); const int worker_id = message.getWorkerID(); switch (message.getType()) { case ForemanMessage::kWorkOrderCompletion: { // Completion of a regular WorkOrder. DEBUG_ASSERT(worker_id >= 0); --queued_workorders_per_op_[response_op_index]; // As the given worker finished executing a WorkOrder, decrement its // number of queued WorkOrders. workers_->decrementNumQueuedWorkOrders(worker_id); // Check if new work orders are available and fetch them if so. fetchNormalWorkOrders( query_dag_->getNodePayloadMutable(response_op_index), response_op_index); if (checkRebuildRequired(response_op_index)) { if (checkNormalExecutionOver(response_op_index)) { if (!checkRebuildInitiated(response_op_index)) { if (initiateRebuild(response_op_index)) { // Rebuild initiated and completed right away. markOperatorFinished(response_op_index); } else { // Rebuild under progress. } } else if (checkRebuildOver(response_op_index)) { // Rebuild was under progress and now it is over. markOperatorFinished(response_op_index); } } else { // Normal execution under progress for this operator. } } else if (checkOperatorExecutionOver(response_op_index)) { // Rebuild not required for this operator and its normal execution is // complete. markOperatorFinished(response_op_index); } for (pair<dag_node_index, bool> dependent_link : query_dag_->getDependents(response_op_index)) { RelationalOperator *dependent_op = query_dag_->getNodePayloadMutable(dependent_link.first); if (checkAllBlockingDependenciesMet(dependent_link.first)) { // Process the dependent operator (of the operator whose WorkOrder // was just executed) for which all the dependencies have been met. processOperator(dependent_op, dependent_link.first, true); } } } break; case ForemanMessage::kRebuildCompletion: { DEBUG_ASSERT(worker_id >= 0); // Completion of a rebuild WorkOrder. --rebuild_status_[response_op_index].second; workers_->decrementNumQueuedWorkOrders(worker_id); if (checkRebuildOver(response_op_index)) { markOperatorFinished(response_op_index); for (pair<dag_node_index, bool> dependent_link : query_dag_->getDependents(response_op_index)) { RelationalOperator *dependent_op = query_dag_->getNodePayloadMutable(dependent_link.first); if (checkAllBlockingDependenciesMet(dependent_link.first)) { processOperator(dependent_op, dependent_link.first, true); } } } } break; case ForemanMessage::kDataPipeline: { // Data streaming message. Possible senders of this message include // InsertDestination and some operators which modify existing blocks. for (dag_node_index consumer_index : output_consumers_[response_op_index]) { RelationalOperator *consumer_op = query_dag_->getNodePayloadMutable(consumer_index); // Feed the streamed block to the consumer. Note that // output_consumers_ only contain those dependents of operator with // index = response_op_index which are eligible to receive streamed // input. consumer_op->feedInputBlock(message.getOutputBlockID(), message.getRelationID()); // Because of the streamed input just fed, check if there are any new // WorkOrders available and if so, fetch them. fetchNormalWorkOrders(consumer_op, consumer_index); } // end for (feeding input to dependents) } break; case ForemanMessage::kWorkOrdersAvailable: { // Check if new work orders are available. fetchNormalWorkOrders( query_dag_->getNodePayloadMutable(response_op_index), response_op_index); break; } default: FATAL_ERROR("Unknown ForemanMessage type"); } // Dispatch the WorkerMessages to the workers. We prefer to start the search // for the schedulable WorkOrders beginning from response_op_index. The first // candidate worker to receive the next WorkOrder is the one that sent the // response message to Foreman. dispatchWorkerMessages(((worker_id >= 0) ? worker_id : 0), response_op_index); return num_operators_finished_ == dag_size; }
void processStatement(SymbolTable *table, Node *ptr) { Node *p; char label1[LABEL_SIZE]={0}, label2[LABEL_SIZE]={0}; switch(ptr->token.tokenNumber) { case COMPOUND_ST: p = ptr->son->next; p = p->son; while (p) { processStatement(table, p); p = p->next; } break; case EXP_ST: if (ptr->son != NULL) { processOperator(table, ptr->son); } break; case RETURN_ST: if (ptr->son != NULL) { p = ptr->son; if (p->noderep == NONTERM) { processOperator(table, p); } else { rv_emit(table, p); } emit0("retv"); } else emit0("ret"); flag_returned=1; break; case IF_ST: genLabel(label1); processCondition(table, ptr->son); emitJump("fjp", label1); processStatement(table, ptr->son->next); emitLabel(label1); break; case IF_ELSE_ST: genLabel(label1); genLabel(label2); processCondition(table, ptr->son); emitJump("fjp", label1); processStatement(table, ptr->son->next); emitJump("ujp", label2); emitLabel(label1); processStatement(table, ptr->son->next->next); emitLabel(label2); break; case WHILE_ST: genLabel(label1); genLabel(label2); emitLabel(label1); processCondition(table, ptr->son); emitJump("fjp", label2); processStatement(table, ptr->son->next); emitJump("ujp", label1); emitLabel(label2); break; default: fprintf(file, "not yet implemented.\n"); break; } }
QueryManager::QueryManager(const tmb::client_id foreman_client_id, const std::size_t num_numa_nodes, QueryHandle *query_handle, CatalogDatabaseLite *catalog_database, StorageManager *storage_manager, tmb::MessageBus *bus) : foreman_client_id_(foreman_client_id), query_id_(DCHECK_NOTNULL(query_handle)->query_id()), catalog_database_(DCHECK_NOTNULL(catalog_database)), storage_manager_(DCHECK_NOTNULL(storage_manager)), bus_(DCHECK_NOTNULL(bus)) { DCHECK(query_handle->getQueryPlanMutable() != nullptr); query_dag_ = query_handle->getQueryPlanMutable()->getQueryPlanDAGMutable(); DCHECK(query_dag_ != nullptr); const dag_node_index num_operators_in_dag = query_dag_->size(); output_consumers_.resize(num_operators_in_dag); blocking_dependencies_.resize(num_operators_in_dag); query_exec_state_.reset(new QueryExecutionState(num_operators_in_dag)); workorders_container_.reset( new WorkOrdersContainer(num_operators_in_dag, num_numa_nodes)); query_context_.reset(new QueryContext(query_handle->getQueryContextProto(), *catalog_database_, storage_manager_, foreman_client_id_, bus_)); for (dag_node_index node_index = 0; node_index < num_operators_in_dag; ++node_index) { const QueryContext::insert_destination_id insert_destination_index = query_dag_->getNodePayload(node_index).getInsertDestinationID(); if (insert_destination_index != QueryContext::kInvalidInsertDestinationId) { // Rebuild is necessary whenever InsertDestination is present. query_exec_state_->setRebuildRequired(node_index); query_exec_state_->setRebuildStatus(node_index, 0, false); } for (const pair<dag_node_index, bool> &dependent_link : query_dag_->getDependents(node_index)) { const dag_node_index dependent_op_index = dependent_link.first; if (!query_dag_->getLinkMetadata(node_index, dependent_op_index)) { // The link is not a pipeline-breaker. Streaming of blocks is possible // between these two operators. output_consumers_[node_index].push_back(dependent_op_index); } else { // The link is a pipeline-breaker. Streaming of blocks is not possible // between these two operators. blocking_dependencies_[dependent_op_index].push_back(node_index); } } } // Collect all the workorders from all the relational operators in the DAG. for (dag_node_index index = 0; index < num_operators_in_dag; ++index) { if (checkAllBlockingDependenciesMet(index)) { query_dag_->getNodePayloadMutable(index)->informAllBlockingDependenciesMet(); processOperator(index, false); } } }