nsbaci 1.0
Loading...
Searching...
No Matches
interpreter.h
Go to the documentation of this file.
1
12
13#ifndef NSBACI_SERVICES_RUNTIME_INTERPRETER_H
14#define NSBACI_SERVICES_RUNTIME_INTERPRETER_H
15
16#include <functional>
17#include <optional>
18#include <string>
19
20#include "baseResult.h"
21#include "drawingTypes.h"
22#include "program.h"
23#include "thread.h"
24
25struct InterpreterResult : nsbaci::BaseResult {
26 InterpreterResult() : BaseResult() {}
27 explicit InterpreterResult(std::vector<nsbaci::Error> errs)
28 : BaseResult(std::move(errs)) {}
29 explicit InterpreterResult(nsbaci::Error error)
30 : BaseResult(std::move(error)) {}
31
32 InterpreterResult(InterpreterResult&&) noexcept = default;
33 InterpreterResult& operator=(InterpreterResult&&) noexcept = default;
34
35 InterpreterResult(const InterpreterResult&) = default;
36 InterpreterResult& operator=(const InterpreterResult&) = default;
37
38 bool needsInput = false;
39 std::string inputPrompt;
40 std::string output;
41
42 // Concurrency control signals
43 bool shouldBlock = false;
44 uint32_t blockingSemaphore = 0;
45 bool shouldYield = false;
46 bool cobeginStart = false;
47 bool coendWait = false;
48 int32_t expectedThreadCount = 0;
49 bool createThread = false;
50 uint32_t newThreadPC = 0;
51 bool signalSemaphore = false;
52 uint32_t signaledSemaphore = 0;
53};
54
60
62using OutputCallback = std::function<void(const std::string&)>;
63
65using InputRequestCallback = std::function<void(const std::string&)>;
66
68using DrawingCallback = std::function<void(const nsbaci::types::DrawCommand&)>;
69
77class Interpreter {
78 public:
79 Interpreter() = default;
80 virtual ~Interpreter() = default;
81
89
94 virtual void provideInput(const std::string& input) = 0;
95
100 virtual bool isWaitingForInput() const = 0;
101
106 virtual void setOutputCallback(OutputCallback callback) = 0;
107
112 virtual void setDrawingCallback(DrawingCallback callback) = 0;
113
118 virtual void reset() = 0;
119};
120
121} // namespace nsbaci::services::runtime
122
123#endif // NSBACI_SERVICES_RUNTIME_INTERPRETER_H
Base result class declaration for nsbaci services.
Represents an error with a message and optional code.
Definition error.h:28
virtual void setOutputCallback(OutputCallback callback)=0
Set the output callback for print operations.
virtual void setDrawingCallback(DrawingCallback callback)=0
Set the drawing callback for drawing operations.
virtual bool isWaitingForInput() const =0
Check if interpreter is waiting for input.
virtual InterpreterResult executeInstruction(Thread &t, Program &program)=0
Executes the current instruction for the given thread with the program context.
virtual void provideInput(const std::string &input)=0
Provide input to a thread waiting for input.
virtual void reset()=0
Reset interpreter state for a new run.
Represents a compiled program ready for execution.
Definition program.h:54
Represents a thread in the runtime service.
Definition thread.h:31
Type definitions for drawing-related operations.
Runtime services namespace for nsbaci.
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
std::function< void(const std::string &)> InputRequestCallback
Callback type for input requests.
Definition interpreter.h:65
Program class declaration for nsbaci runtime service.
Definition interpreter.h:25
bool createThread
Should create a new thread.
Definition interpreter.h:49
bool shouldBlock
Thread should be blocked (semaphore wait).
Definition interpreter.h:43
std::string output
Output produced by this instruction.
Definition interpreter.h:40
bool coendWait
Waiting for cobegin threads to finish.
Definition interpreter.h:47
int32_t expectedThreadCount
Number of threads to wait for at coend.
Definition interpreter.h:48
bool signalSemaphore
Signal was called on a semaphore.
Definition interpreter.h:51
bool shouldYield
Thread should yield after instruction.
Definition interpreter.h:45
bool needsInput
Thread is waiting for input.
Definition interpreter.h:38
uint32_t newThreadPC
PC for new thread (if createThread is true).
Definition interpreter.h:50
std::string inputPrompt
Prompt to show for input.
Definition interpreter.h:39
uint32_t blockingSemaphore
Address of semaphore causing block.
Definition interpreter.h:44
uint32_t signaledSemaphore
Address of semaphore that was signaled.
Definition interpreter.h:52
bool cobeginStart
Starting a cobegin block.
Definition interpreter.h:46
Base result structure for all service operations.
Definition baseResult.h:56
BaseResult()
Default constructor creates a successful result.
Definition baseResult.h:60
Represents a single drawing command to be executed.
Definition drawingTypes.h:240
Thread class declaration for nsbaci runtime service.