#include "vector" #include "vm-src.h" #include "stack.h" #include "command-exec.h" #include using std::vector; using std::byte; using std::cout; const unsigned char showByte (byte b) { return char(b); } const unsigned char * showBytes (byte* bytes) { for (int i=0;i bytes) { std::string showTxt = ""; for (byte b : bytes) { // showTxt += char(b); showTxt += vmSrc_getByteText(b); } return showTxt; } void VirtualMachine::includeVoid (Subprog subprog) { this->subprogs.push_back(subprog); // Отладка /*cout << "Function ( " << vmSrc_showBytes(subprog.id) << "):\n"; for (vector com : subprog.commandBytes) { cout << vmSrc_showBytes(com) << "\n"; }*/ } vector> VirtualMachine::parseCommands (vector allByteCode, int byteCodeLength) { vector> parsedData {}; vector activeCommand {}; vector buffer {}; int activeCommandLength = 0; for (int i = 0; i < byteCodeLength; i++) { buffer.push_back(allByteCode[i]); //std::cout << vmSrc_getByteText(allByteCode[i]) << "\n"; if (activeCommandLength == 0) { //byte activeCommand[] = { allByteCode[i] }; activeCommand.push_back(allByteCode[i]); activeCommandLength = 1; } else if (activeCommandLength == 1) { activeCommand.push_back(allByteCode[i]); activeCommandLength = 2; } else { // Начинаем парсинг //std::cout << vmSrc_showBytes(allByteCode) << "\n"; Stack stack; CommandExecutor comExec(buffer, stack); if (comExec.isCommandDefined) { if (comExec.isEnded) { parsedData.push_back(comExec.bytes); activeCommand.clear(); activeCommandLength = 0; buffer.clear(); } } else { // (!) Тут выдать ошибку : undefined command std::cout << int(activeCommand[0]) << "x" << int(activeCommand.at(1)) << " -> Required definitation\n"; } } } return parsedData; } void VirtualMachine::bindStopPoints (int* stopPoints) {} VirtualMachine::VirtualMachine (bool isDebugModeOn) { this->isDebugging = isDebugModeOn; } void VirtualMachine::debugModeOutput () { /* Out conditions of stacks, functions, heap, etc.*/ /* Example: */ /* |==========DEBUG MODE===========| |Program condition | |_______________________________| |Condition |Value | |Stack used |11 bytes | |Heap used | | |_______________________________| |Stack | |_______________________________| |Void_id |ID|Length|Data | |0x00000000|2 |2 |0x1AFE | |0x00000000|1 |3 |0x1FEA00 | |0x00000000|0 |1 |0xDE | |0x000000FA|1 |4 |0x00FA9077| |0x000000FA|0 |1 |0xFF | |_______________________________| */ }