Add comprehensive tests for ProcessKernel and Usecode VM functionality
- Implemented tests for ProcessKernel in entity_dispatch_entry_tests.cpp, covering process creation, termination, and scanning of runnable processes. - Enhanced fixed_map_tests.cpp with tests for item allocation and release, including recycling of items and process ownership. - Expanded flex_archive_tests.cpp to validate the interaction between usecode events and item processes, ensuring correct behavior of spawned tasks and rendering. - Introduced usecode_vm_tests.cpp to thoroughly test the UsecodeInterpreterState and UsecodeProcessTask functionalities, including stack operations and opcode services.
This commit is contained in:
parent
e757bb33d0
commit
08a907f322
14 changed files with 1784 additions and 34 deletions
|
|
@ -5,15 +5,28 @@
|
|||
namespace remorse {
|
||||
|
||||
std::optional<UsecodeInterpreterState> UsecodeInterpreterState::initialize(
|
||||
const std::vector<u8>& itemParameter)
|
||||
const std::vector<u8>& itemParameter, const std::vector<u8>& contextParameter,
|
||||
u16 modeFlags)
|
||||
{
|
||||
if (itemParameter.size() > 0xcc) {
|
||||
const bool saveStackPointer = !contextParameter.empty() && modeFlags != 0;
|
||||
const std::size_t savedPointerBytes = saveStackPointer ? sizeof(FarPtr16) : 0;
|
||||
if (itemParameter.size() > usecodeInterpreterStackLimit ||
|
||||
contextParameter.size() > usecodeInterpreterStackLimit - itemParameter.size() ||
|
||||
savedPointerBytes > usecodeInterpreterStackLimit - itemParameter.size() - contextParameter.size()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
UsecodeInterpreterState state;
|
||||
state.stackTop -= itemParameter.size();
|
||||
std::copy(itemParameter.begin(), itemParameter.end(),
|
||||
state.valueStack.begin() + state.stackTop);
|
||||
state.stackHighWatermark = state.valueStack.size();
|
||||
const auto pushBytes = [&state](const std::vector<u8>& bytes) {
|
||||
state.stackTop -= bytes.size();
|
||||
std::copy(bytes.begin(), bytes.end(), state.valueStack.begin() + state.stackTop);
|
||||
};
|
||||
pushBytes(itemParameter);
|
||||
pushBytes(contextParameter);
|
||||
if (saveStackPointer) {
|
||||
state.stackTop -= savedPointerBytes;
|
||||
state.contextParameterOffset = static_cast<u16>(state.stackTop - sizeof(u16) * 2);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
@ -26,4 +39,484 @@ bool UsecodeInterpreterState::pushCodeAddress(u16 offset, u16 segment)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool UsecodeInterpreterState::pushWord(u16 value)
|
||||
{
|
||||
if (stackTop < sizeof(value)) {
|
||||
return false;
|
||||
}
|
||||
stackTop -= sizeof(value);
|
||||
valueStack[stackTop] = static_cast<u8>(value);
|
||||
valueStack[stackTop + 1] = static_cast<u8>(value >> 8);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UsecodeInterpreterState::pushDword(u32 value)
|
||||
{
|
||||
if (stackTop < sizeof(value)) {
|
||||
return false;
|
||||
}
|
||||
stackTop -= sizeof(value);
|
||||
for (std::size_t index = 0; index < sizeof(value); ++index) {
|
||||
valueStack[stackTop + index] = static_cast<u8>(value >> (index * 8));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<u16> UsecodeInterpreterState::popWord()
|
||||
{
|
||||
if (stackTop > stackHighWatermark || stackHighWatermark > valueStack.size() ||
|
||||
stackHighWatermark - stackTop < sizeof(u16)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const u16 value = static_cast<u16>(valueStack[stackTop] |
|
||||
(static_cast<u16>(valueStack[stackTop + 1]) << 8));
|
||||
stackTop += sizeof(u16);
|
||||
return value;
|
||||
}
|
||||
|
||||
std::optional<u32> UsecodeInterpreterState::popDword()
|
||||
{
|
||||
if (stackTop > stackHighWatermark || stackHighWatermark > valueStack.size() ||
|
||||
stackHighWatermark - stackTop < sizeof(u32)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
u32 value = 0;
|
||||
for (std::size_t index = 0; index < sizeof(value); ++index) {
|
||||
value |= static_cast<u32>(valueStack[stackTop + index]) << (index * 8);
|
||||
}
|
||||
stackTop += sizeof(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
UsecodeStepResult UsecodeInterpreterState::step(const std::vector<u8>& code,
|
||||
std::size_t& programCounter, std::vector<u8>& frame,
|
||||
const UsecodeOpcodeServices& services)
|
||||
{
|
||||
if (programCounter >= code.size()) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const u8 opcode = code[programCounter++];
|
||||
if (opcode == 0x00 || opcode == 0x01 || opcode == 0x3e || opcode == 0x3f) {
|
||||
if (programCounter >= code.size()) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const auto rawOffset = static_cast<s8>(code[programCounter]);
|
||||
const auto localIndex = static_cast<std::ptrdiff_t>(usecodeFrameBaseOffset) + rawOffset;
|
||||
const bool byteOperation = opcode == 0x00 || opcode == 0x3e;
|
||||
const std::size_t valueSize = byteOperation ? sizeof(u8) : sizeof(u16);
|
||||
if (localIndex < 0 || static_cast<std::size_t>(localIndex) > frame.size() ||
|
||||
frame.size() - static_cast<std::size_t>(localIndex) < valueSize) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const std::size_t localOffset = static_cast<std::size_t>(localIndex);
|
||||
if (opcode == 0x3e) {
|
||||
++programCounter;
|
||||
return pushWord(frame[localOffset])
|
||||
? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x3f) {
|
||||
++programCounter;
|
||||
const u16 value = static_cast<u16>(frame[localOffset] |
|
||||
(static_cast<u16>(frame[localOffset + 1]) << 8));
|
||||
return pushWord(value) ? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (stackTop > valueStack.size() - sizeof(u16)) {
|
||||
return UsecodeStepResult::StackFault;
|
||||
}
|
||||
++programCounter;
|
||||
if (opcode == 0x00) {
|
||||
frame[localOffset] = valueStack[stackTop];
|
||||
} else {
|
||||
frame[localOffset] = valueStack[stackTop];
|
||||
frame[localOffset + 1] = valueStack[stackTop + 1];
|
||||
}
|
||||
return popWord() ? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x0a) {
|
||||
if (programCounter >= code.size()) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const auto value = static_cast<s16>(static_cast<s8>(code[programCounter++]));
|
||||
return pushWord(static_cast<u16>(value))
|
||||
? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x0c) {
|
||||
if (code.size() - programCounter < sizeof(u32)) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
u32 value = 0;
|
||||
for (std::size_t index = 0; index < sizeof(value); ++index) {
|
||||
value |= static_cast<u32>(code[programCounter + index]) << (index * 8);
|
||||
}
|
||||
programCounter += sizeof(value);
|
||||
return pushDword(value) ? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x0f) {
|
||||
const std::size_t instructionStart = programCounter - 1;
|
||||
if (code.size() - programCounter < 3) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const u8 argumentBytes = code[programCounter];
|
||||
const u16 ordinal = static_cast<u16>(code[programCounter + 1] |
|
||||
(static_cast<u16>(code[programCounter + 2]) << 8));
|
||||
if (!services.callIntrinsic) {
|
||||
programCounter = instructionStart;
|
||||
return UsecodeStepResult::UnsupportedOpcode;
|
||||
}
|
||||
if (argumentBytes > valueStack.size() - stackTop) {
|
||||
return UsecodeStepResult::StackFault;
|
||||
}
|
||||
const auto result = services.callIntrinsic(ordinal, argumentBytes,
|
||||
valueStack.data() + stackTop);
|
||||
if (!result) {
|
||||
programCounter = instructionStart;
|
||||
return UsecodeStepResult::ServiceRejected;
|
||||
}
|
||||
programCounter += 3;
|
||||
temporaryWord = *result;
|
||||
return UsecodeStepResult::Advanced;
|
||||
}
|
||||
if (opcode == 0x14 || opcode == 0x1c || opcode == 0x24 || opcode == 0x2a ||
|
||||
opcode == 0x2c || opcode == 0x36) {
|
||||
const auto right = popWord();
|
||||
const auto left = right ? popWord() : std::nullopt;
|
||||
if (!left || !right) {
|
||||
if (right) pushWord(*right);
|
||||
return UsecodeStepResult::StackFault;
|
||||
}
|
||||
u16 result = 0;
|
||||
if (opcode == 0x14) result = static_cast<u16>(*left + *right);
|
||||
else if (opcode == 0x1c) result = static_cast<u16>(*left - *right);
|
||||
else if (opcode == 0x24) result = static_cast<u16>(*left == *right);
|
||||
else if (opcode == 0x2a) result = static_cast<u16>(*left <= *right);
|
||||
else if (opcode == 0x2c) result = static_cast<u16>(static_cast<s16>(*left) > static_cast<s16>(*right));
|
||||
else result = static_cast<u16>(*left != *right);
|
||||
return pushWord(result) ? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x51 || opcode == 0x52) {
|
||||
if (code.size() - programCounter < sizeof(u16)) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const s16 relativeOffset = static_cast<s16>(code[programCounter] |
|
||||
(static_cast<u16>(code[programCounter + 1]) << 8));
|
||||
programCounter += sizeof(u16);
|
||||
bool shouldJump = opcode == 0x52;
|
||||
if (opcode == 0x51) {
|
||||
const auto condition = popWord();
|
||||
if (!condition) {
|
||||
return UsecodeStepResult::StackFault;
|
||||
}
|
||||
shouldJump = *condition == 0;
|
||||
}
|
||||
if (shouldJump) {
|
||||
const auto target = static_cast<std::ptrdiff_t>(programCounter) + relativeOffset;
|
||||
if (target < 0 || static_cast<std::size_t>(target) >= code.size()) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
programCounter = static_cast<std::size_t>(target);
|
||||
}
|
||||
return UsecodeStepResult::Advanced;
|
||||
}
|
||||
if (opcode == 0x53) {
|
||||
return UsecodeStepResult::Yielded;
|
||||
}
|
||||
if (opcode == 0x54) {
|
||||
if (code.size() - programCounter < 2) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
programCounter += 2;
|
||||
if (!popWord()) {
|
||||
return UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (temporaryWord >= 3) {
|
||||
impliedProcessId = temporaryWord;
|
||||
}
|
||||
return UsecodeStepResult::Advanced;
|
||||
}
|
||||
if (opcode == 0x59) {
|
||||
if (!services.currentProcessId) {
|
||||
--programCounter;
|
||||
return UsecodeStepResult::UnsupportedOpcode;
|
||||
}
|
||||
currentProcessId = services.currentProcessId();
|
||||
return pushWord(currentProcessId)
|
||||
? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x5d) {
|
||||
return pushWord(static_cast<u8>(temporaryWord))
|
||||
? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x6e) {
|
||||
if (programCounter >= code.size()) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const auto adjustment = static_cast<s8>(code[programCounter++]);
|
||||
const auto newTop = static_cast<std::ptrdiff_t>(stackTop) - adjustment;
|
||||
if (newTop < 0 || newTop > static_cast<std::ptrdiff_t>(valueStack.size())) {
|
||||
return UsecodeStepResult::StackFault;
|
||||
}
|
||||
stackTop = static_cast<std::size_t>(newTop);
|
||||
stackHighWatermark = std::max(stackHighWatermark, stackTop);
|
||||
return UsecodeStepResult::Advanced;
|
||||
}
|
||||
if (opcode == 0x12) {
|
||||
const auto value = popWord();
|
||||
if (!value) {
|
||||
return UsecodeStepResult::StackFault;
|
||||
}
|
||||
temporaryWord = *value;
|
||||
return UsecodeStepResult::Advanced;
|
||||
}
|
||||
if (opcode == 0x0b) {
|
||||
if (code.size() - programCounter < 2) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const u16 value = static_cast<u16>(code[programCounter] |
|
||||
(static_cast<u16>(code[programCounter + 1]) << 8));
|
||||
programCounter += 2;
|
||||
return pushWord(value) ? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x40) {
|
||||
if (programCounter >= code.size()) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const std::size_t localOffset = code[programCounter++];
|
||||
const std::size_t localIndex = usecodeFrameBaseOffset + localOffset;
|
||||
if (localIndex > frame.size() || frame.size() - localIndex < sizeof(u32)) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const u32 value = static_cast<u32>(frame[localIndex]) |
|
||||
(static_cast<u32>(frame[localIndex + 1]) << 8) |
|
||||
(static_cast<u32>(frame[localIndex + 2]) << 16) |
|
||||
(static_cast<u32>(frame[localIndex + 3]) << 24);
|
||||
return pushDword(value) ? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x4c) {
|
||||
if (programCounter >= code.size()) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const std::size_t valueSize = code[programCounter++];
|
||||
if (valueSize != sizeof(u16)) {
|
||||
return UsecodeStepResult::UnsupportedOpcode;
|
||||
}
|
||||
const auto address = popDword();
|
||||
if (!address) {
|
||||
return UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (!services.readFarWord) {
|
||||
pushDword(*address);
|
||||
return UsecodeStepResult::ServiceRejected;
|
||||
}
|
||||
const auto value = services.readFarWord(static_cast<u16>(*address),
|
||||
static_cast<u16>(*address >> 16));
|
||||
if (!value) {
|
||||
pushDword(*address);
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
return pushWord(*value) ? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x77) {
|
||||
if (!services.setInfo) {
|
||||
--programCounter;
|
||||
return UsecodeStepResult::UnsupportedOpcode;
|
||||
}
|
||||
const auto first = popWord();
|
||||
const auto second = first ? popWord() : std::nullopt;
|
||||
if (!first || !second) {
|
||||
if (first) pushWord(*first);
|
||||
return UsecodeStepResult::StackFault;
|
||||
}
|
||||
lastSetInfoOperands = std::array<u16, 2>{*first, *second};
|
||||
if (!services.setInfo(*second, *first)) {
|
||||
pushWord(*second);
|
||||
pushWord(*first);
|
||||
return UsecodeStepResult::ServiceRejected;
|
||||
}
|
||||
return UsecodeStepResult::SetInfo;
|
||||
}
|
||||
if (opcode == 0x50) {
|
||||
return UsecodeStepResult::Returned;
|
||||
}
|
||||
if (opcode == 0x57) {
|
||||
const std::size_t instructionStart = programCounter - 1;
|
||||
if (code.size() - programCounter < 6) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
const u8 extraArgumentBytes = code[programCounter];
|
||||
const u8 itemArgumentSize = code[programCounter + 1];
|
||||
const u16 classId = static_cast<u16>(code[programCounter + 2] |
|
||||
(static_cast<u16>(code[programCounter + 3]) << 8));
|
||||
const u16 eventSlot = static_cast<u16>(code[programCounter + 4] |
|
||||
(static_cast<u16>(code[programCounter + 5]) << 8));
|
||||
if ((itemArgumentSize != 0 && itemArgumentSize != sizeof(u16)) ||
|
||||
stackTop > valueStack.size() - sizeof(u32) ||
|
||||
extraArgumentBytes > valueStack.size() - stackTop - sizeof(u32)) {
|
||||
--programCounter;
|
||||
return UsecodeStepResult::UnsupportedOpcode;
|
||||
}
|
||||
if (!services.spawn || (itemArgumentSize != 0 && !services.readFarWord)) {
|
||||
--programCounter;
|
||||
return UsecodeStepResult::UnsupportedOpcode;
|
||||
}
|
||||
const auto itemPointer = popDword();
|
||||
if (!itemPointer) {
|
||||
return UsecodeStepResult::StackFault;
|
||||
}
|
||||
u16 itemArgument = 0;
|
||||
if (itemArgumentSize == sizeof(u16)) {
|
||||
const auto value = services.readFarWord(static_cast<u16>(*itemPointer),
|
||||
static_cast<u16>(*itemPointer >> 16));
|
||||
if (!value) {
|
||||
pushDword(*itemPointer);
|
||||
programCounter = instructionStart;
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
itemArgument = *value;
|
||||
}
|
||||
const u8* extraArguments = valueStack.data() + stackTop;
|
||||
programCounter += 6;
|
||||
const auto processId = services.spawn(classId, eventSlot, extraArgumentBytes,
|
||||
itemArgumentSize, itemArgument, extraArguments);
|
||||
if (!processId) {
|
||||
pushDword(*itemPointer);
|
||||
programCounter = instructionStart;
|
||||
return UsecodeStepResult::ServiceRejected;
|
||||
}
|
||||
temporaryWord = *processId;
|
||||
return UsecodeStepResult::Spawned;
|
||||
}
|
||||
if (opcode == 0x5b) {
|
||||
if (code.size() - programCounter < 2) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
programCounter += 2;
|
||||
return UsecodeStepResult::Advanced;
|
||||
}
|
||||
if (opcode == 0x5c) {
|
||||
constexpr std::size_t symbolInfoBytes = 11;
|
||||
if (code.size() - programCounter < symbolInfoBytes) {
|
||||
return UsecodeStepResult::InvalidInstruction;
|
||||
}
|
||||
programCounter += symbolInfoBytes;
|
||||
return UsecodeStepResult::Advanced;
|
||||
}
|
||||
if (opcode == 0x5e) {
|
||||
return pushWord(temporaryWord) ? UsecodeStepResult::Advanced : UsecodeStepResult::StackFault;
|
||||
}
|
||||
if (opcode == 0x78) {
|
||||
if (!services.processCount) {
|
||||
--programCounter;
|
||||
return UsecodeStepResult::UnsupportedOpcode;
|
||||
}
|
||||
processExcluded = services.processCount() > 1;
|
||||
return UsecodeStepResult::Advanced;
|
||||
}
|
||||
--programCounter;
|
||||
return UsecodeStepResult::UnsupportedOpcode;
|
||||
}
|
||||
|
||||
std::optional<UsecodeProcessTask> UsecodeProcessTask::create(u16 processId, u16 classId,
|
||||
u16 eventSlot, u16 sourceItem, std::vector<u8> code, u8 itemArgumentSize,
|
||||
std::vector<u8> extraArguments, std::vector<u8> contextParameter)
|
||||
{
|
||||
if (processId < 3 || code.size() <= usecodeEventBytecodeOffset ||
|
||||
(itemArgumentSize != 0 && itemArgumentSize != sizeof(u16))) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const std::vector<u8> itemParameter = itemArgumentSize == 0 ? std::vector<u8>{}
|
||||
: std::vector<u8>{static_cast<u8>(sourceItem), static_cast<u8>(sourceItem >> 8)};
|
||||
auto interpreter = UsecodeInterpreterState::initialize(itemParameter, contextParameter,
|
||||
itemArgumentSize);
|
||||
if (!interpreter) {
|
||||
return std::nullopt;
|
||||
}
|
||||
UsecodeProcessTask task;
|
||||
task.processId = processId;
|
||||
task.classId = classId;
|
||||
task.eventSlot = eventSlot;
|
||||
task.sourceItem = sourceItem;
|
||||
task.code = std::move(code);
|
||||
task.frame.resize(0x80);
|
||||
task.itemMemory.resize(0x102);
|
||||
task.itemMemory[0x100] = static_cast<u8>(sourceItem);
|
||||
task.itemMemory[0x101] = static_cast<u8>(sourceItem >> 8);
|
||||
std::size_t argumentOffset = usecodeFrameBaseOffset + 6;
|
||||
if (itemArgumentSize == sizeof(u16)) {
|
||||
task.frame[argumentOffset] = 0x00;
|
||||
task.frame[argumentOffset + 1] = 0x01;
|
||||
argumentOffset += sizeof(u32);
|
||||
}
|
||||
if (extraArguments.size() > task.frame.size() - argumentOffset) {
|
||||
return std::nullopt;
|
||||
}
|
||||
std::copy(extraArguments.begin(), extraArguments.end(), task.frame.begin() + argumentOffset);
|
||||
task.interpreter = std::move(*interpreter);
|
||||
return task;
|
||||
}
|
||||
|
||||
std::optional<u16> UsecodeProcessTask::readMappedItemWord(FarPtr16 address) const
|
||||
{
|
||||
if (address.segment != 0 || address.offset > itemMemory.size() ||
|
||||
itemMemory.size() - address.offset < sizeof(u16)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return static_cast<u16>(itemMemory[address.offset] |
|
||||
(static_cast<u16>(itemMemory[address.offset + 1]) << 8));
|
||||
}
|
||||
|
||||
bool writeUsecodeContextFactoryFields(u8* processBytes, std::size_t processSize,
|
||||
const UsecodeContextFactoryFields& fields)
|
||||
{
|
||||
if (processBytes == nullptr || processSize < usecodeContextProcessSize) {
|
||||
return false;
|
||||
}
|
||||
const auto writeWord = [processBytes](std::size_t offset, u16 value) {
|
||||
processBytes[offset] = static_cast<u8>(value);
|
||||
processBytes[offset + 1] = static_cast<u8>(value >> 8);
|
||||
};
|
||||
writeWord(usecodeContextSlotIndexOffset, fields.slotIndex);
|
||||
writeWord(usecodeContextValueAddOffset, fields.valueAddOffset);
|
||||
writeWord(usecodeContextOwnerSourceOffset, fields.ownerSource.offset);
|
||||
writeWord(usecodeContextOwnerSourceOffset + sizeof(u16), fields.ownerSource.segment);
|
||||
writeWord(usecodeContextParameterOffset, fields.parameterOffset);
|
||||
processBytes[usecodeContextModeFlagsOffset] = static_cast<u8>(fields.modeFlags);
|
||||
processBytes[usecodeContextActiveFlagOffset] = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
UsecodeStepResult UsecodeProcessTask::step(const UsecodeOpcodeServices& services)
|
||||
{
|
||||
if (halted) {
|
||||
return UsecodeStepResult::Returned;
|
||||
}
|
||||
const auto result = interpreter.step(code, programCounter, frame, services);
|
||||
halted = result == UsecodeStepResult::Returned;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool UsecodeTaskRegistry::add(UsecodeProcessTask task)
|
||||
{
|
||||
if (task.processId < 3) {
|
||||
return false;
|
||||
}
|
||||
return tasks_.emplace(task.processId, std::move(task)).second;
|
||||
}
|
||||
|
||||
UsecodeProcessTask* UsecodeTaskRegistry::find(u16 processId)
|
||||
{
|
||||
const auto found = tasks_.find(processId);
|
||||
return found == tasks_.end() ? nullptr : &found->second;
|
||||
}
|
||||
|
||||
const UsecodeProcessTask* UsecodeTaskRegistry::find(u16 processId) const
|
||||
{
|
||||
const auto found = tasks_.find(processId);
|
||||
return found == tasks_.end() ? nullptr : &found->second;
|
||||
}
|
||||
|
||||
bool UsecodeTaskRegistry::remove(u16 processId)
|
||||
{
|
||||
return tasks_.erase(processId) != 0;
|
||||
}
|
||||
|
||||
} // namespace remorse
|
||||
Loading…
Add table
Add a link
Reference in a new issue