void DeclarationAssignmentStatementNode::Code(InstructionsClass & machineCode) { in->DeclareVariable(); machineCode.PushValue(0); machineCode.PopAndStore(in->GetIndex()); en->CodeEvaluate(machineCode); machineCode.PopAndStore(in->GetIndex()); }
void TimesAssignmentStatementNode::Code(InstructionsClass &machinecode) { MSG(" CODING MINUSASSIGNMENTSTATEMENTNODE"); this->mIdentifierNode->CodeEvaluate(machinecode); this->mExpressionNode->CodeEvaluate(machinecode); machinecode.PopPopMulPush(); machinecode.PopAndStore(this->mIdentifierNode->GetIndex()); }
void DivideAssignmentStatementNode::Code(InstructionsClass &machineCode) { // push vars value on stack machineCode.PushVariable(in->GetIndex()); // put modifier on stack en->CodeEvaluate(machineCode); // divide those values machineCode.PopPopDivPush(); // store result machineCode.PopAndStore(in->GetIndex()); }
int main( void ) { cout << "in main of teste.cpp\n"; // Create an array of machine codes, and stuff it with initial // machine codes that are at the beginning of every function: InstructionsClass code; // Generate machine code to push a literal integer onto the stack: code.PushValue(17); // Generate machine code to pop and print integer on top of stack: code.PopAndWrite(); // Generate machine code to push a literal integer onto the stack: code.PushValue(27); // Generate machine code to pop the top of stack and move to variable index 99: code.PopAndStore(99); // Generate machine code to push variable 99's contents onto the stack: code.PushVariable(99); // (holds int 27 from before) // Generate machine code to pop and print integer on top of stack: code.PopAndWrite(); // Generate machine code to return to the calling code: code.Finish(); // Treat the array of machine codes like a function, and jump in! code.Execute(); return 0; }
void IfStatementNode::Code(InstructionsClass &machinecode) { MSG(" CODING IFSTATEMENTNODE"); this->mExpressionNode->CodeEvaluate(machinecode); unsigned char * jump_address = machinecode.SkipIfZeroStack(); unsigned char * address1 = machinecode.GetAddress(); this->mStatementNode->Code(machinecode); unsigned char * address2 = machinecode.GetAddress(); machinecode.SetOffset(jump_address, address2 - address1); }
void CoutStatementNode::Code(InstructionsClass &machineCode) { for (unsigned int i = 0; i < ens.size(); i++) { if (ens.at(i) == NULL) { machineCode.WriteEndl(); } else { ens.at(i)->CodeEvaluate(machineCode); machineCode.PopAndWrite(); } } }
void IfStatementNode::Code(InstructionsClass &machineCode) { // evaluate test and put on stack test->CodeEvaluate(machineCode); // get variable to record 'size' of block unsigned char* jump_address = machineCode.SkipIfZeroStack(); // measure block 'size' unsigned char* block_start = machineCode.GetAddress(); block->Code(machineCode); unsigned char* block_end = machineCode.GetAddress(); // set variable that records 'size' of block machineCode.SetOffset(jump_address, block_end - block_start); }
void CoutStatementNode::Code(InstructionsClass &machinecode) { MSG(" CODING COUTSTATEMENTNODE"); for (unsigned int i = 0; i < this->mExpressionNodes.size(); i++) { if (this->mExpressionNodes[i]) { this->mExpressionNodes[i]->CodeEvaluate(machinecode); machinecode.PopAndWrite(); } else { machinecode.WriteEndl(); } } //this->mExpressionNode->CodeEvaluate(machinecode); //machinecode.PopAndWrite(); }
void WhileStatementNode::Code(InstructionsClass &machineCode) { // store beginning of while evaluate unsigned char* begin_address = machineCode.GetAddress(); // evaluate test and put on stack test->CodeEvaluate(machineCode); // get variable to record 'size' of block unsigned char* jump_address = machineCode.SkipIfZeroStack(); // measure block 'size' unsigned char* block_start = machineCode.GetAddress(); block->Code(machineCode); unsigned char* jump_address2 = machineCode.Jump(); unsigned char* block_end = machineCode.GetAddress(); // set variable that records 'size' of block machineCode.SetOffset(jump_address, block_end - block_start); // set variable that jumps to the while loop evaluate machineCode.SetOffset(jump_address2, begin_address - block_end); }
void LessNode::CodeEvaluate(InstructionsClass & machineCode) { lhs->CodeEvaluate(machineCode); rhs->CodeEvaluate(machineCode); machineCode.PopPopLessPush(); }
void DivideNode::CodeEvaluate(InstructionsClass & machineCode) { lhs->CodeEvaluate(machineCode); rhs->CodeEvaluate(machineCode); machineCode.PopPopDivPush(); }
void TimesNode::CodeEvaluate(InstructionsClass & machineCode) { lhs->CodeEvaluate(machineCode); rhs->CodeEvaluate(machineCode); machineCode.PopPopMulPush(); }
void MinusNode::CodeEvaluate(InstructionsClass & machineCode) { lhs->CodeEvaluate(machineCode); rhs->CodeEvaluate(machineCode); machineCode.PopPopSubPush(); }
void TimesNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING TIMENODE"); mLeft->CodeEvaluate(machinecode); mRight->CodeEvaluate(machinecode); machinecode.PopPopMulPush(); }
void PlusNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING PLUSNODE"); mLeft->CodeEvaluate(machinecode); mRight->CodeEvaluate(machinecode); machinecode.PopPopAddPush(); }
void AndNode::CodeEvaluate(InstructionsClass & machineCode) { lhs->CodeEvaluate(machineCode); rhs->CodeEvaluate(machineCode); machineCode.PopPopAndPush(); }
void IdentifierNode::CodeEvaluate(InstructionsClass &machineCode) { machineCode.PushVariable(table->GetIndex(label)); }
void NotEqualNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING NOTEQUALNODE"); mLeft->CodeEvaluate(machinecode); mRight->CodeEvaluate(machinecode); machinecode.PopPopNotEqualPush(); }
void IdentifierNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING IDENTIFIERNODE"); machinecode.PushVariable(this->mSymbolTable->GetIndex(this->mLabel)); }
void GreaterEqualNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING GREATEREQUALNODE"); mLeft->CodeEvaluate(machinecode); mRight->CodeEvaluate(machinecode); machinecode.PopPopGreaterEqualPush(); }
void LessNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING LESSNODE"); mLeft->CodeEvaluate(machinecode); mRight->CodeEvaluate(machinecode); machinecode.PopPopLessPush(); }
void DivideNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING DIVIDENODE"); mLeft->CodeEvaluate(machinecode); mRight->CodeEvaluate(machinecode); machinecode.PopPopDivPush(); }
void GreaterNode::CodeEvaluate(InstructionsClass & machineCode) { lhs->CodeEvaluate(machineCode); rhs->CodeEvaluate(machineCode); machineCode.PopPopGreaterPush(); }
void AndNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING ANDNODE"); mLeft->CodeEvaluate(machinecode); mRight->CodeEvaluate(machinecode); machinecode.PopPopAndPush(); }
void NotEqualNode::CodeEvaluate(InstructionsClass & machineCode) { lhs->CodeEvaluate(machineCode); rhs->CodeEvaluate(machineCode); machineCode.PopPopNotEqualPush(); }
void MinusNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING MINUSNODE"); mLeft->CodeEvaluate(machinecode); mRight->CodeEvaluate(machinecode); machinecode.PopPopSubPush(); }
void NotNode::CodeEvaluate(InstructionsClass & machineCode) { expression->CodeEvaluate(machineCode); machineCode.LogicalNot(); }
void IntegerNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING INTEGERNODE"); machinecode.PushValue(this->mValue); }
void AssignmentStatementNode::Code(InstructionsClass &machineCode) { en->CodeEvaluate(machineCode); machineCode.PopAndStore(in->GetIndex()); }
void OrNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING ORNODE"); mLeft->CodeEvaluate(machinecode); mRight->CodeEvaluate(machinecode); machinecode.PopPopOrPush(); }