#include #include #include #include namespace regexis024 { bool CAEvent::operator==(const CAEvent &other) const { return (key == other.key) && (value == other.value); } #define reveal ((VMContext*)opaque) VirtualMachine::VirtualMachine(size_t programSize, const uint8_t *data, uint64_t caTreeLimit, tai_t saLenLimit, sslot_id_t readSsLimit, sslot_id_t forkSsLimit, uint64_t timeTickLimit) { opaque = new VMContext(programSize, data, caTreeLimit, saLenLimit, readSsLimit, forkSsLimit, timeTickLimit); } error_code_t VirtualMachine::initialize() { if (gave_SOF) throw std::runtime_error("double feedSOF\n"); gave_SOF = true; return reveal->feedSOF(); } bool VirtualMachine::isInitialized() { return reveal->initialized; } bool VirtualMachine::isUsable() { return isInitialized() && reveal->error == error_codes::stable; } VirtualMachine::~VirtualMachine() { delete reveal; } tai_t VirtualMachine::getSelectionArrayLength() { return isUsable() ? reveal->selection_array_len : 0; } bool VirtualMachine::isAllowMultistart() { return isUsable() ? reveal->allows_multistart : false; } uint8_t VirtualMachine::getInputLeftExtensionSize() { return isUsable() ? reveal->fed_input_extends_left : 0; } uint8_t VirtualMachine::getInputRightExtensionSize() { return isUsable() ? reveal->fed_input_extends_right : 0; } error_code_t VirtualMachine::getErrno() { return reveal->error; } /* Stupid kinda function. Checks if somebody is ready to continue reading the actual string or extended l-r input */ bool VirtualMachine::haveSurvivors() { return isUsable() && (!reveal->READ_halted_stack_new_first.empty() || !reveal->READ_halted_stack_new_second.empty()); } bool VirtualMachine::isMatched() { return isUsable() && static_cast((reveal->matched_thread.slot_occupation_status & SLOT_OCCUPIED)); } std::vector VirtualMachine::getMatchedThreadCABranchReverse() { if (!isMatched()) return {}; std::vector res; CollectionArrayNode* cur = reveal->matched_thread.CAHptr; while (cur != NULL){ res.push_back({cur->key, cur->value}); cur = cur->prev; } return res; } uint64_t VirtualMachine::getMatchedThreadSAValue(uint16_t key) { if (key >= getSelectionArrayLength()) return 0; if (!isMatched()) return 0; return reveal->matched_thread.SAptr ? reveal->matched_thread.SAptr[key + 1] : 0; } error_code_t VirtualMachine::addNewMatchingThread() { if (!isUsable()) throw std::runtime_error("unusable"); return reveal->startThread(); } error_code_t VirtualMachine::extendedFeedCharacter(uint64_t input) { if (!isUsable()) throw std::runtime_error("unusable\n"); return reveal->extendedFeedCharacter(input); } error_code_t VirtualMachine::feedCharacter(uint64_t input, uint64_t bytesResembled) { if (!isUsable()) throw std::runtime_error("unusable\n"); return reveal->feedCharacter(input, bytesResembled); } }