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 DeclarationAssignmentStatementNode::Code(InstructionsClass & machineCode) { in->DeclareVariable(); machineCode.PushValue(0); machineCode.PopAndStore(in->GetIndex()); en->CodeEvaluate(machineCode); machineCode.PopAndStore(in->GetIndex()); }
void IntegerNode::CodeEvaluate(InstructionsClass &machinecode) { MSG("\tCODING INTEGERNODE"); machinecode.PushValue(this->mValue); }