16 #include <unordered_map>
31 explicit Actor(
const std::shared_ptr<VM>& vm,
const address_t variableSize);
42 bool SyncCall(const int32_t priority, const
char* action, const std::shared_ptr<
Actor>& sender);
43 bool AsyncCall(const int32_t priority, const
char* action, const std::shared_ptr<
Actor>& sender);
45 bool Request(const int32_t priority, const
char* action, const std::shared_ptr<
Actor>& sender);
46 void Rollback(const int32_t priority);
50 uint32_t
GetAction(const std::string_view& actionName) const;
70 #if MANA_BUILD_TARGET < MANA_BUILD_RELEASE
71 [[nodiscard]] std::string_view GetActorName()
const;
72 void SetActorName(
const std::string_view& name);
73 [[nodiscard]] std::string GetActionName()
const;
74 [[nodiscard]] std::string_view GetFunctionName()
const;
81 void Repeat(
const bool initialComplete);
100 void SetAction(
const std::string_view& actionName,
const uint32_t address);
104 static constexpr int32_t LowestInterruptPriority = std::numeric_limits<int32_t>::lowest();
105 static constexpr uint32_t Nil =
static_cast<uint32_t
>(~0);
108 struct Interrupt final
110 std::shared_ptr<Actor> mSender;
111 uint32_t mAddress = Nil;
112 uint32_t mReturnAddress = Nil;
115 std::bitset<8> mFlag = 0;
116 #if MANA_BUILD_TARGET < MANA_BUILD_RELEASE
117 std::string mActionName;
120 enum class Flag : uint8_t
131 struct ReturnValue final
137 const char* mStringValue;
143 static constexpr int32_t Invalid = 0;
144 static constexpr int32_t
Actor = -1;
145 static constexpr int32_t Integer = -2;
146 static constexpr int32_t Float = -3;
147 static constexpr int32_t String = -4;
152 mValues.mPointerValue =
nullptr;
156 std::weak_ptr<VM> mVM;
157 std::unordered_map <std::string_view, uint32_t> mActions;
160 std::map<int32_t, Interrupt> mInterrupts;
161 ReturnValue mReturnValue;
162 Event<int32_t, int32_t> mOnPriorityChanged;
165 int32_t mInterruptPriority = LowestInterruptPriority;
166 std::bitset<8> mFlag = 0;
167 enum class Flag : uint8_t
177 #if MANA_BUILD_TARGET < MANA_BUILD_RELEASE
178 std::string_view mName;
182 static void CommandRestart(
const std::shared_ptr<VM>& vm,
Actor&
self);
183 static void CommandHalt(
const std::shared_ptr<VM>& vm,
Actor&
self);
184 static void CommandYield(
const std::shared_ptr<VM>& vm,
Actor&
self);
185 static void CommandSetNonPreemptive(
const std::shared_ptr<VM>& vm,
Actor&
self);
186 static void CommandSetPreemptive(
const std::shared_ptr<VM>& vm,
Actor&
self);
187 static void CommandPushZeroInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
188 static void CommandPushZeroFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
189 static void CommandPushChar(
const std::shared_ptr<VM>& vm,
Actor&
self);
190 static void CommandPushShort(
const std::shared_ptr<VM>& vm,
Actor&
self);
191 static void CommandPushInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
192 static void CommandPushFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
193 static void CommandPushString(
const std::shared_ptr<VM>& vm,
Actor&
self);
194 static void CommandPushPriority(
const std::shared_ptr<VM>& vm,
Actor&
self);
195 static void CommandPushSelf(
const std::shared_ptr<VM>& vm,
Actor&
self);
196 static void CommandPushSender(
const std::shared_ptr<VM>& vm,
Actor&
self);
197 static void CommandAllocate(
const std::shared_ptr<VM>& vm,
Actor&
self);
198 static void CommandRelease(
const std::shared_ptr<VM>& vm,
Actor&
self);
199 static void CommandDuplicate(
const std::shared_ptr<VM>& vm,
Actor&
self);
200 static void CommandRemove(
const std::shared_ptr<VM>& vm,
Actor&
self);
201 static void CommandLoadStaticAddress(
const std::shared_ptr<VM>& vm,
Actor&
self);
202 static void CommandLoadGlobalAddress(
const std::shared_ptr<VM>& vm,
Actor&
self);
203 static void CommandLoadFrameAddress(
const std::shared_ptr<VM>& vm,
Actor&
self);
204 static void CommandLoadSelfAddress(
const std::shared_ptr<VM>& vm,
Actor&
self);
205 static void CommandLoadInt8(
const std::shared_ptr<VM>& vm,
Actor&
self);
206 static void CommandLoadInt16(
const std::shared_ptr<VM>& vm,
Actor&
self);
207 static void CommandLoadInt32(
const std::shared_ptr<VM>& vm,
Actor&
self);
208 static void CommandLoadFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
209 static void CommandLoadReference(
const std::shared_ptr<VM>& vm,
Actor&
self);
210 static void CommandStoreInt8(
const std::shared_ptr<VM>& vm,
Actor&
self);
211 static void CommandStoreInt16(
const std::shared_ptr<VM>& vm,
Actor&
self);
212 static void CommandStoreInt32(
const std::shared_ptr<VM>& vm,
Actor&
self);
213 static void CommandStoreFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
214 static void CommandStoreReference(
const std::shared_ptr<VM>& vm,
Actor&
self);
215 static void CommandBranchEqual(
const std::shared_ptr<VM>& vm,
Actor&
self);
216 static void CommandBranchNotEqual(
const std::shared_ptr<VM>& vm,
Actor&
self);
217 static void CommandBranchAway(
const std::shared_ptr<VM>& vm,
Actor&
self);
218 static void CommandBranchSubRoutine(
const std::shared_ptr<VM>& vm,
Actor&
self);
219 static void CommandCall(
const std::shared_ptr<VM>& vm,
Actor&
self);
220 static void CommandRequest(
const std::shared_ptr<VM>& vm,
Actor&
self);
221 static void CommandRequestWaitStarting(
const std::shared_ptr<VM>& vm,
Actor&
self);
222 static void CommandRequestWaitEnding(
const std::shared_ptr<VM>& vm,
Actor&
self);
223 static void CommandDynamicRequest(
const std::shared_ptr<VM>& vm,
Actor&
self);
224 static void CommandDynamicRequestWaitStarting(
const std::shared_ptr<VM>& vm,
Actor&
self);
225 static void CommandDynamicRequestWaitEnded(
const std::shared_ptr<VM>& vm,
Actor&
self);
226 static void CommandJoin(
const std::shared_ptr<VM>& vm,
Actor&
self);
227 static void CommandComply(
const std::shared_ptr<VM>& vm,
Actor&
self);
228 static void CommandRefuse(
const std::shared_ptr<VM>& vm,
Actor&
self);
229 static void CommandLoadReturnAddress(
const std::shared_ptr<VM>& vm,
Actor&
self);
230 static void CommandStoreReturnAddress(
const std::shared_ptr<VM>& vm,
Actor&
self);
231 static void CommandReturnFromFunction(
const std::shared_ptr<VM>& vm,
Actor&
self);
232 static void CommandReturnFromAction(
const std::shared_ptr<VM>& vm,
Actor&
self);
233 static void CommandRollback(
const std::shared_ptr<VM>& vm,
Actor&
self);
234 static void CommandAddInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
235 static void CommandAddFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
236 static void CommandDivideInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
237 static void CommandDivideFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
238 static void CommandMinusInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
239 static void CommandMinusFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
240 static void CommandModInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
241 static void CommandModFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
242 static void CommandMultiplyInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
243 static void CommandMultiplyFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
244 static void CommandSubtractInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
245 static void CommandSubtractFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
246 static void CommandAnd(
const std::shared_ptr<VM>& vm,
Actor&
self);
247 static void CommandExclusiveOr(
const std::shared_ptr<VM>& vm,
Actor&
self);
248 static void CommandLogicalAnd(
const std::shared_ptr<VM>& vm,
Actor&
self);
249 static void CommandLogicalOr(
const std::shared_ptr<VM>& vm,
Actor&
self);
250 static void CommandNot(
const std::shared_ptr<VM>& vm,
Actor&
self);
251 static void CommandLogicalNot(
const std::shared_ptr<VM>& vm,
Actor&
self);
252 static void CommandOr(
const std::shared_ptr<VM>& vm,
Actor&
self);
253 static void CommandShiftLeft(
const std::shared_ptr<VM>& vm,
Actor&
self);
254 static void CommandShiftRight(
const std::shared_ptr<VM>& vm,
Actor&
self);
255 static void CommandCompareEqualInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
256 static void CommandCompareEqualFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
257 static void CommandCompareGreaterEqualInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
258 static void CommandCompareGreaterEqualFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
259 static void CommandCompareGreaterInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
260 static void CommandCompareGreaterFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
261 static void CommandCompareNotEqualInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
262 static void CommandCompareNotEqualFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
263 static void CommandCompareLessEqualInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
264 static void CommandCompareLessEqualFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
265 static void CommandCompareLessInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
266 static void CommandCompareLessFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
267 static void CommandIntegerToFloat(
const std::shared_ptr<VM>& vm,
Actor&
self);
268 static void CommandFloatToInteger(
const std::shared_ptr<VM>& vm,
Actor&
self);
269 static void CommandPushActor(
const std::shared_ptr<VM>& vm,
Actor&
self);
270 static void CommandLoadData(
const std::shared_ptr<VM>& vm,
Actor&
self);
271 static void CommandStoreData(
const std::shared_ptr<VM>& vm,
Actor&
self);
272 static void CommandDuplicateData(
const std::shared_ptr<VM>& vm,
Actor&
self);
273 static void CommandRemoveData(
const std::shared_ptr<VM>& vm,
Actor&
self);
274 static void CommandCompareEqualData(
const std::shared_ptr<VM>& vm,
Actor&
self);
275 static void CommandCompareGreaterEqualData(
const std::shared_ptr<VM>& vm,
Actor&
self);
276 static void CommandCompareGreaterData(
const std::shared_ptr<VM>& vm,
Actor&
self);
277 static void CommandCompareNotEqualData(
const std::shared_ptr<VM>& vm,
Actor&
self);
278 static void CommandCompareLessEqualData(
const std::shared_ptr<VM>& vm,
Actor&
self);
279 static void CommandCompareLessData(
const std::shared_ptr<VM>& vm,
Actor&
self);
280 static void CommandPrint(
const std::shared_ptr<VM>& vm,
Actor&
self);
284 #if MANA_BUILD_TARGET > MANA_BUILD_DEBUG
286 #define MANA_ASSERT_PARAMETER(P, I) { \
287 if(P->GetArgumentCount() != I) \
291 #define MANA_ASSERT_ILLIGAL_CALL_IN_INIT_ACTION(P) { \
292 if(P->GetVirtualMachine()->IsInInitAction()){ \
297 #define MANA_ASSERT_PARAMETER(P, I) \
298 if((P)->GetArgumentCount() != (I)){ \
299 MANA_PRINT({ "ERROR: ", (P)->GetName(), ": function ", (P)->GetFunctionName(), " number of arguments ", std::to_string((P)->GetArgumentCount()), " correct ", std::to_string(I), "\n" });\
303 #define MANA_ASSERT_CANT_CALL_IN_INIT_ACTION(P) \
304 if((P)->GetVirtualMachine()->IsInInitAction()){ \
305 MANA_PRINT({ "ERROR: ", (P)->GetName(), ": init action ", (P)->GetFunctionName()," can not call\n" });\
Actor(const std::shared_ptr< VM > &vm, const address_t variableSize)
Constructor.
Definition: Actor.inl:14
bool Run()
Definition: Actor.inl:29
int32_t GetInterruptPriority() const
Definition: Actor.inl:752
void SetReturnActor(const std::shared_ptr< Actor > &actor)
Definition: Actor.inl:616
void Again()
Definition: Actor.inl:709
bool IsRunning() const
Definition: Actor.inl:688
void SetReturnString(const char *string)
Definition: Actor.inl:610
void Repeat(const bool initialComplete)
Definition: Actor.inl:695
void yield()
Definition: Actor.inl:734
int32_t GetArgumentSize(const uint32_t address) const
Definition: Actor.inl:546
void Stop()
Definition: Actor.inl:729
void Restart()
Definition: Actor.inl:502
bool SyncCall(const int32_t priority, const char *action, const std::shared_ptr< Actor > &sender)
Definition: Actor.inl:224
void SetSynchronized(const bool synchronized)
Definition: Actor.inl:765
void SetSynchronizedWithPriority(const int32_t priority, const bool synchronized)
Definition: Actor.inl:776
bool IsCommandRepeat() const
Definition: Actor.inl:680
void SetReturnFloat(const float value)
Definition: Actor.inl:604
bool Request(const int32_t priority, const char *action, const std::shared_ptr< Actor > &sender)
Definition: Actor.inl:260
std::string_view GetName()
Definition: Actor.inl:518
bool IsCommandInitialized() const
Definition: Actor.inl:672
EventNameType AddPriorityChangedEvent(const std::function< void(int32_t, int32_t)> &function)
Definition: Actor.inl:787
int32_t GetArgumentCountByAddress(const uint32_t address) const
Definition: Actor.inl:540
bool IsSynchronized() const
Definition: Actor.inl:757
Actor(const Actor &)=delete
void SetReturnPointer(void *pointer)
Definition: Actor.inl:622
float GetParameterFloat(const int32_t value) const
Definition: Actor.inl:562
bool HasReturnValue(const uint32_t address) const
Definition: Actor.inl:551
void SetReturnInteger(const int32_t value)
Definition: Actor.inl:598
void SetReturnData(const void *pointer, const int32_t size)
Definition: Actor.inl:628
void * GetParameterAddress(const int32_t value) const
Definition: Actor.inl:592
Actor(Actor &&) noexcept=delete
void * GetParameterPointer(const int32_t value) const
Definition: Actor.inl:586
void Rollback(const int32_t priority)
Definition: Actor.inl:383
void Refuse()
Definition: Actor.inl:747
std::shared_ptr< Actor > Clone() const
Definition: Actor.inl:21
void RemovePriorityChangedEvent(const EventNameType eventName)
Definition: Actor.inl:792
bool AsyncCall(const int32_t priority, const char *action, const std::shared_ptr< Actor > &sender)
Definition: Actor.inl:242
void Accept()
Definition: Actor.inl:742
int32_t GetArgumentCount() const
Definition: Actor.inl:534
Stack & GetStack()
Definition: Actor.inl:797
std::shared_ptr< VM > GetVirtualMachine() const
Definition: Actor.inl:667
std::shared_ptr< Actor > GetParameterActor(const int32_t value) const
Definition: Actor.inl:574
void Halt()
Definition: Actor.inl:715
int32_t GetParameterInteger(const int32_t value) const
Definition: Actor.inl:556
uint32_t GetAction(const std::string_view &actionName) const
Definition: Actor.inl:523
Actor * GetParameterActorPointer(const int32_t value) const
Definition: Actor.inl:581
const char * GetParameterString(const int32_t value) const
Definition: Actor.inl:568
Definition: CodeBuffer.cpp:12
std::uint32_t address_t
Definition: Type.h:30
std::int32_t int_t
Definition: Type.h:28
float float_t
Definition: Type.h:27
uint32_t EventNameType
Definition: Event.h:15
Definition: Noncopyable.h:18