HiveMind
BittyBuzzVm.h
Go to the documentation of this file.
1 #ifndef __BITTYBUZZVM_H_
2 #define __BITTYBUZZVM_H_
3 
4 #include "IBittyBuzzBytecode.h"
10 #include "IBittyBuzzVm.h"
12 #include <array>
13 #include <bsp/IBSP.h>
14 #include <bsp/IUserInterface.h>
15 #include <logger/ILogger.h>
16 
17 class BittyBuzzVm : public IBittyBuzzVm {
18  public:
31  BittyBuzzVm(const IBittyBuzzBytecode& bytecode,
32  const IBittyBuzzStringResolver& stringResolver,
33  IBittyBuzzMessageHandler& messageHandler,
34  IBittyBuzzClosureRegister& closureRegister,
35  IBittyBuzzMessageService& messageService,
36  IBittyBuzzNeighborsManager& neighborsManager,
37  IUserUI& userUI,
38  IBSP& bsp,
39  ILogger& logger,
40  IUserInterface& ui);
41 
42  ~BittyBuzzVm() override = default;
43 
44  bool init(const std::reference_wrapper<IBittyBuzzLib>* bbzLibs,
45  uint32_t bbzLibsLength) override;
46 
47  bool start() override;
48 
49  void stop() override;
50 
51  BBVMRet step() override;
52 
53  void terminate() override;
54 
55  void logDump(LogLevel logLevel) override;
56 
57  bbzvm_state getState() const override;
58 
59  bbzvm_error getError() const override;
60 
61  bbzvm_instr getInstruction() const override;
62 
63  private:
65  const IBSP& m_bsp;
72 
73  bbzvm_t m_bbzVm;
74 };
75 
76 #endif // __BITTYBUZZVM_H_
BittyBuzzVm::m_bsp
const IBSP & m_bsp
Definition: BittyBuzzVm.h:65
BBVMRet
BBVMRet
Definition: IBittyBuzzVm.h:10
IBittyBuzzClosureRegister
A class to register buzz function/closures id and associate them with a string.
Definition: IBittyBuzzClosureRegister.h:24
IBittyBuzzMessageService.h
IBSP.h
BittyBuzzVm::start
bool start() override
Starts the vm.
Definition: BittyBuzzVm.cpp:64
IUserUI.h
IBittyBuzzNeighborsManager.h
BittyBuzzVm::terminate
void terminate() override
Terminate the virtual machine and removes all messages that were supposed to be processed.
Definition: BittyBuzzVm.cpp:80
BittyBuzzVm::m_bbzVm
bbzvm_t m_bbzVm
Definition: BittyBuzzVm.h:73
BittyBuzzVm
Definition: BittyBuzzVm.h:17
LogLevel
LogLevel
The log level used for the logger.
Definition: ILogger.h:9
BittyBuzzVm::init
bool init(const std::reference_wrapper< IBittyBuzzLib > *bbzLibs, uint32_t bbzLibsLength) override
Init the virtual machine.
Definition: BittyBuzzVm.cpp:38
IUserUI
Manages the UI available to the user.
Definition: IUserUI.h:7
IBittyBuzzNeighborsManager
Definition: IBittyBuzzNeighborsManager.h:4
BittyBuzzVm::m_ui
IUserInterface & m_ui
Definition: BittyBuzzVm.h:71
IBittyBuzzVm
Manages BittyBuzz virtual machine.
Definition: IBittyBuzzVm.h:14
IBittyBuzzClosureRegister.h
BittyBuzzVm::m_closureRegister
IBittyBuzzClosureRegister & m_closureRegister
Definition: BittyBuzzVm.h:69
IBSP
Definition: IBSP.h:6
IBittyBuzzStringResolver
Class that resolves a string from the bittybuzz virtual machine.
Definition: IBittyBuzzStringResolver.h:10
IBittyBuzzVm.h
BittyBuzzVm::~BittyBuzzVm
~BittyBuzzVm() override=default
BittyBuzzVm::m_messageService
IBittyBuzzMessageService & m_messageService
Definition: BittyBuzzVm.h:67
BittyBuzzVm::getInstruction
bbzvm_instr getInstruction() const override
Get the current instruction of the VM.
Definition: BittyBuzzVm.cpp:126
IUserInterface.h
BittyBuzzVm::m_logger
ILogger & m_logger
Definition: BittyBuzzVm.h:70
BittyBuzzVm::getState
bbzvm_state getState() const override
Get the state of the vm.
Definition: BittyBuzzVm.cpp:122
IBittyBuzzBytecode.h
ILogger
A logger class with basic logging capabilities.
Definition: ILogger.h:35
BittyBuzzVm::step
BBVMRet step() override
Does one execution step in the virtual machine. Thus execute the buzz code in the step function.
Definition: BittyBuzzVm.cpp:90
IBittyBuzzStringResolver.h
BittyBuzzVm::stop
void stop() override
Stops the vm, can be called in another thread or in an interrupt.
Definition: BittyBuzzVm.cpp:73
BittyBuzzVm::m_messageHandler
IBittyBuzzMessageHandler & m_messageHandler
Definition: BittyBuzzVm.h:66
IBittyBuzzMessageService
message service use by the BBVM. Constructs the messages and dispatches it at the appropriate place (...
Definition: IBittyBuzzMessageService.h:9
BittyBuzzVm::logDump
void logDump(LogLevel logLevel) override
Logs the virtual machine state, stack, heap and table segments.
Definition: BittyBuzzVm.cpp:78
BittyBuzzVm::m_bytecode
const IBittyBuzzBytecode & m_bytecode
Definition: BittyBuzzVm.h:64
IUserInterface
Manages the user interface The user interface can consist of buttons, LED, serial print ports,...
Definition: IUserInterface.h:36
BittyBuzzVm::m_neighborsManager
IBittyBuzzNeighborsManager & m_neighborsManager
Definition: BittyBuzzVm.h:68
IBittyBuzzBytecode
Manages the BittyBuzz byte code.
Definition: IBittyBuzzBytecode.h:9
IBittyBuzzMessageHandler
Handles messages destined to the bbvm.
Definition: IBittyBuzzMessageHandler.h:8
IBittyBuzzMessageHandler.h
BittyBuzzVm::BittyBuzzVm
BittyBuzzVm(const IBittyBuzzBytecode &bytecode, const IBittyBuzzStringResolver &stringResolver, IBittyBuzzMessageHandler &messageHandler, IBittyBuzzClosureRegister &closureRegister, IBittyBuzzMessageService &messageService, IBittyBuzzNeighborsManager &neighborsManager, IUserUI &userUI, IBSP &bsp, ILogger &logger, IUserInterface &ui)
The constructor of the bbvm.
Definition: BittyBuzzVm.cpp:9
BittyBuzzVm::getError
bbzvm_error getError() const override
Get the error state of the VM.
Definition: BittyBuzzVm.cpp:124
ILogger.h