nsbaci 1.0
Loading...
Searching...
No Matches
runtimeService.h
Go to the documentation of this file.
1
14
15#ifndef NSBACI_RUNTIMESERVICE_H
16#define NSBACI_RUNTIMESERVICE_H
17
18#include <memory>
19
20#include "baseResult.h"
21#include "interpreter.h"
22#include "program.h"
23#include "scheduler.h"
24
29namespace nsbaci::services {
30
40
45 explicit RuntimeResult(std::vector<nsbaci::Error> errs)
46 : BaseResult(std::move(errs)) {}
47
52 explicit RuntimeResult(nsbaci::Error error) : BaseResult(std::move(error)) {}
53
54 RuntimeResult(RuntimeResult&&) noexcept = default;
55 RuntimeResult& operator=(RuntimeResult&&) noexcept = default;
56 RuntimeResult(const RuntimeResult&) = default;
57 RuntimeResult& operator=(const RuntimeResult&) = default;
58
59 bool halted = false;
60 bool needsInput = false;
61 std::string inputPrompt;
62 std::string output;
63};
64
81
105 public:
113 RuntimeService() = default;
114
120 RuntimeService(std::unique_ptr<runtime::Interpreter> i,
121 std::unique_ptr<runtime::Scheduler> s);
122
126 ~RuntimeService() = default;
127
128 RuntimeService(const RuntimeService&) = delete;
129 RuntimeService& operator=(const RuntimeService&) = delete;
130
131 RuntimeService(RuntimeService&&) = default;
132 RuntimeService& operator=(RuntimeService&&) = default;
133
145
152 void reset();
153
163
172 RuntimeResult stepThread(nsbaci::types::ThreadID threadId);
173
186 RuntimeResult run(size_t maxSteps = 0);
187
193 void pause();
194
199 RuntimeState getState() const;
200
205 bool isHalted() const;
206
211 size_t threadCount() const;
212
217 const std::vector<runtime::Thread>& getThreads() const;
218
224 const runtime::Program& getProgram() const;
225
234 void provideInput(const std::string& input);
235
240 bool isWaitingForInput() const;
241
251
261
262 private:
264 program;
265 std::unique_ptr<runtime::Interpreter>
266 interpreter;
267 std::unique_ptr<runtime::Scheduler>
268 scheduler;
270};
271
272} // namespace nsbaci::services
273
274#endif // NSBACI_RUNTIMESERVICE_H
Base result class declaration for nsbaci services.
Represents an error with a message and optional code.
Definition error.h:28
const runtime::Program & getProgram() const
Gets the loaded program.
Definition runtimeService.cpp:173
RuntimeState getState() const
Gets the current runtime state.
Definition runtimeService.cpp:154
RuntimeService()=default
Default constructor creates an uninitialized service.
RuntimeResult run(size_t maxSteps=0)
Runs the program until halted, error, or step limit.
Definition runtimeService.cpp:126
bool isWaitingForInput() const
Checks if the runtime is waiting for user input.
Definition runtimeService.cpp:182
void loadProgram(runtime::Program &&p)
Loads a compiled program for execution.
Definition runtimeService.cpp:20
bool isHalted() const
Checks if the program has finished execution.
Definition runtimeService.cpp:156
const std::vector< runtime::Thread > & getThreads() const
Gets all threads from the scheduler.
Definition runtimeService.cpp:165
RuntimeResult stepThread(nsbaci::types::ThreadID threadId)
Executes a single instruction for a specific thread.
Definition runtimeService.cpp:120
void pause()
Pauses continuous execution.
Definition runtimeService.cpp:148
size_t threadCount() const
Gets the number of active threads.
Definition runtimeService.cpp:158
void setOutputCallback(runtime::OutputCallback callback)
Sets the callback for output operations.
Definition runtimeService.cpp:189
void provideInput(const std::string &input)
Provides input to the runtime.
Definition runtimeService.cpp:175
RuntimeResult step()
Executes a single instruction for any ready thread.
Definition runtimeService.cpp:42
void setDrawingCallback(runtime::DrawingCallback callback)
Sets the callback for drawing operations.
Definition runtimeService.cpp:195
void reset()
Resets the runtime to initial state.
Definition runtimeService.cpp:25
~RuntimeService()=default
Default destructor.
Represents a compiled program ready for execution.
Definition program.h:54
Interpreter class declaration for nsbaci runtime service.
std::function< void(const std::string &)> OutputCallback
Callback type for output operations.
Definition interpreter.h:62
std::function< void(const nsbaci::types::DrawCommand &)> DrawingCallback
Callback type for drawing operations.
Definition interpreter.h:68
Services namespace containing all backend service implementations.
Definition compilerService.cpp:15
RuntimeState
Possible states of the runtime service.
Definition runtimeService.h:75
@ Running
Program is actively executing.
Definition runtimeService.h:77
@ Halted
Program has finished execution.
Definition runtimeService.h:79
@ Idle
No program loaded or ready to start.
Definition runtimeService.h:76
@ Paused
Execution paused, can step or continue.
Definition runtimeService.h:78
Program class declaration for nsbaci runtime service.
Scheduler class declaration for nsbaci runtime service.
Base result structure for all service operations.
Definition baseResult.h:56
BaseResult()
Default constructor creates a successful result.
Definition baseResult.h:60
Result of a runtime operation (step, run, etc.).
Definition runtimeService.h:35
RuntimeResult(std::vector< nsbaci::Error > errs)
Constructs a result from a vector of errors.
Definition runtimeService.h:45
std::string output
Output produced by this step.
Definition runtimeService.h:62
RuntimeResult(nsbaci::Error error)
Constructs a failed result from a single error.
Definition runtimeService.h:52
RuntimeResult()
Default constructor creates a successful result.
Definition runtimeService.h:39
bool needsInput
True if waiting for user input.
Definition runtimeService.h:60
std::string inputPrompt
Prompt to show for input.
Definition runtimeService.h:61
bool halted
True if program has terminated.
Definition runtimeService.h:59