![]() |
nsbaci 1.0
|
Service that manages program execution. More...
#include <runtimeService.h>
Public Member Functions | |
| RuntimeService ()=default | |
| Default constructor creates an uninitialized service. | |
| RuntimeService (std::unique_ptr< runtime::Interpreter > i, std::unique_ptr< runtime::Scheduler > s) | |
| Constructs a RuntimeService with interpreter and scheduler. | |
| ~RuntimeService ()=default | |
| Default destructor. | |
| RuntimeService (const RuntimeService &)=delete | |
| RuntimeService & | operator= (const RuntimeService &)=delete |
| RuntimeService (RuntimeService &&)=default | |
| RuntimeService & | operator= (RuntimeService &&)=default |
| void | loadProgram (runtime::Program &&p) |
| Loads a compiled program for execution. | |
| void | reset () |
| Resets the runtime to initial state. | |
| RuntimeResult | step () |
| Executes a single instruction for any ready thread. | |
| RuntimeResult | stepThread (nsbaci::types::ThreadID threadId) |
| Executes a single instruction for a specific thread. | |
| RuntimeResult | run (size_t maxSteps=0) |
| Runs the program until halted, error, or step limit. | |
| void | pause () |
| Pauses continuous execution. | |
| RuntimeState | getState () const |
| Gets the current runtime state. | |
| bool | isHalted () const |
| Checks if the program has finished execution. | |
| size_t | threadCount () const |
| Gets the number of active threads. | |
| const std::vector< runtime::Thread > & | getThreads () const |
| Gets all threads from the scheduler. | |
| const runtime::Program & | getProgram () const |
| Gets the loaded program. | |
| void | provideInput (const std::string &input) |
| Provides input to the runtime. | |
| bool | isWaitingForInput () const |
| Checks if the runtime is waiting for user input. | |
| void | setOutputCallback (runtime::OutputCallback callback) |
| Sets the callback for output operations. | |
| void | setDrawingCallback (runtime::DrawingCallback callback) |
| Sets the callback for drawing operations. | |
Service that manages program execution.
The service is move-only to ensure single ownership of the interpreter and scheduler components.
Usage example:
|
default |
Default constructor creates an uninitialized service.
A service created this way must have its interpreter and scheduler set before use, typically via move assignment from a factory-created instance.


| nsbaci::services::RuntimeService::RuntimeService | ( | std::unique_ptr< runtime::Interpreter > | i, |
| std::unique_ptr< runtime::Scheduler > | s ) |
Constructs a RuntimeService with interpreter and scheduler.
| i | Unique pointer to the interpreter implementation. |
| s | Unique pointer to the scheduler implementation. |
| const runtime::Program & nsbaci::services::RuntimeService::getProgram | ( | ) | const |
Gets the loaded program.

| RuntimeState nsbaci::services::RuntimeService::getState | ( | ) | const |
Gets the current runtime state.

| const std::vector< runtime::Thread > & nsbaci::services::RuntimeService::getThreads | ( | ) | const |
Gets all threads from the scheduler.

| bool nsbaci::services::RuntimeService::isHalted | ( | ) | const |
Checks if the program has finished execution.

| bool nsbaci::services::RuntimeService::isWaitingForInput | ( | ) | const |
Checks if the runtime is waiting for user input.

| void nsbaci::services::RuntimeService::loadProgram | ( | runtime::Program && | p | ) |
Loads a compiled program for execution.
Initializes the runtime with the program's instructions, symbol table, and memory. Creates the initial main thread and sets state to Paused ready for execution.
| p | The compiled program to load (which must be moved into the service). |


| void nsbaci::services::RuntimeService::pause | ( | ) |
Pauses continuous execution.
Only affects state if currently Running; changes state to Paused.

| void nsbaci::services::RuntimeService::provideInput | ( | const std::string & | input | ) |
Provides input to the runtime.
Called when the user provides input in response to a Read instruction. The input is stored and will be consumed on the next execution step.
| input | The user-provided input string. |

| void nsbaci::services::RuntimeService::reset | ( | ) |
Resets the runtime to initial state.
Clears all threads, resets memory, and sets state to Idle. The program must be reloaded before execution can continue.


| RuntimeResult nsbaci::services::RuntimeService::run | ( | size_t | maxSteps = 0 | ) |
Runs the program until halted, error, or step limit.
Executes instructions continuously until:
| maxSteps | Maximum instructions to execute (0 = unlimited). |


| void nsbaci::services::RuntimeService::setDrawingCallback | ( | runtime::DrawingCallback | callback | ) |
Sets the callback for drawing operations.
The callback is invoked whenever the program performs drawing operations (setColor, drawCircle, fillRect, etc.).
| callback | Function to call with DrawCommand objects. |

| void nsbaci::services::RuntimeService::setOutputCallback | ( | runtime::OutputCallback | callback | ) |
Sets the callback for output operations.
The callback is invoked whenever the program produces output (Write, Writeln, WriteRawString instructions).
| callback | Function to call with output strings. |

| RuntimeResult nsbaci::services::RuntimeService::step | ( | ) |
Executes a single instruction for any ready thread.
The scheduler picks the next thread to run and the interpreter executes one instruction from that thread's current position.


| RuntimeResult nsbaci::services::RuntimeService::stepThread | ( | nsbaci::types::ThreadID | threadId | ) |
Executes a single instruction for a specific thread.
Allows targeted debugging by stepping only the specified thread.
| threadId | The ID of the thread to step. |


| size_t nsbaci::services::RuntimeService::threadCount | ( | ) | const |
Gets the number of active threads.
