void WhileStatementNode::Code(InstructionsClass &machinecode) { MSG(" CODING WHILESTATEMENTNODE"); unsigned char * address0 = machinecode.GetAddress(); this->mExpressionNode->CodeEvaluate(machinecode); unsigned char * jump_address1 = machinecode.SkipIfZeroStack(); unsigned char * address1 = machinecode.GetAddress(); this->mStatementNode->Code(machinecode); unsigned char * jump_address2 = machinecode.Jump(); unsigned char * address2 = machinecode.GetAddress(); machinecode.SetOffset(jump_address1, address2 - address1); machinecode.SetOffset(jump_address2, address0 - address2); }
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); }