16 #include <unordered_map>
33 explicit Actor(
const std::shared_ptr<VM>& vm,
const address_t variableSize);
37 using Callback = int32_t (*)(
const std::shared_ptr<Actor>& actor,
void* parameter);
49 bool SyncCall(const int32_t priority, const
char* action, const std::shared_ptr<
Actor>& sender);
50 bool AsyncCall(const int32_t priority, const
char* action, const std::shared_ptr<
Actor>& sender);
52 bool Request(const int32_t priority, const
char* action, const std::shared_ptr<
Actor>& sender);
53 void Rollback(const int32_t priority);
56 const std::string_view&
GetName();
57 uint32_t
GetAction(const std::string_view& actionName) const;
76 #if MANA_BUILD_TARGET < MANA_BUILD_RELEASE
77 [[nodiscard]] std::string_view GetActorName()
const;
78 void SetActorName(
const std::string_view& name);
79 [[nodiscard]] std::string GetActionName()
const;
80 [[nodiscard]]
const std::string_view GetFunctionName()
const;
87 void Repeat(
const bool initialComplete);
113 void SetAction(
const std::string_view& actionName,
const uint32_t address);
117 static constexpr uint32_t Nil =
static_cast<uint32_t
>(~0);
120 struct Interrupt final
122 std::shared_ptr<Actor> mSender;
123 uint32_t mAddress = Nil;
124 uint32_t mReturnAddress = Nil;
127 void* mFileCallbackParameter =
nullptr;
128 std::bitset<8> mFlag = 0;
129 #if MANA_BUILD_TARGET < MANA_BUILD_RELEASE
130 std::string mActionName;
133 enum class Flag : uint8_t
144 struct ReturnValue final
150 const char* mStringValue;
156 static constexpr int32_t Invalid = 0;
157 static constexpr int32_t Actor = -1;
158 static constexpr int32_t Integer = -2;
159 static constexpr int32_t Float = -3;
160 static constexpr int32_t String = -4;
165 mValues.mPointerValue =
nullptr;
169 std::weak_ptr<VM> mVM;
170 std::unordered_map <std::string_view, uint32_t> mActions;
173 std::map<int32_t, Interrupt> mInterrupts;
174 ReturnValue mReturnValue;
175 Event<int32_t> mRequestEvent;
176 Event<int32_t> mRollbackEvent;
179 int32_t mInterruptPriority = 0;
180 std::bitset<8> mFlag = 0;
181 enum class Flag : uint8_t
190 uintptr_t mUserData = 0;
191 void* mUserPointer =
nullptr;
193 #if MANA_BUILD_TARGET < MANA_BUILD_RELEASE
194 std::string_view mName;
198 static void CommandRestart(
const std::shared_ptr<VM>& vm, Actor&
self);
199 static void CommandHalt(
const std::shared_ptr<VM>& vm, Actor&
self);
200 static void CommandYield(
const std::shared_ptr<VM>& vm, Actor&
self);
201 static void CommandSetNonPreemptive(
const std::shared_ptr<VM>& vm, Actor&
self);
202 static void CommandSetPreemptive(
const std::shared_ptr<VM>& vm, Actor&
self);
203 static void CommandPushZeroInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
204 static void CommandPushZeroFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
205 static void CommandPushChar(
const std::shared_ptr<VM>& vm, Actor&
self);
206 static void CommandPushShort(
const std::shared_ptr<VM>& vm, Actor&
self);
207 static void CommandPushInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
208 static void CommandPushFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
209 static void CommandPushString(
const std::shared_ptr<VM>& vm, Actor&
self);
210 static void CommandPushPriority(
const std::shared_ptr<VM>& vm, Actor&
self);
211 static void CommandPushSelf(
const std::shared_ptr<VM>& vm, Actor&
self);
212 static void CommandPushSender(
const std::shared_ptr<VM>& vm, Actor&
self);
213 static void CommandAllocate(
const std::shared_ptr<VM>& vm, Actor&
self);
214 static void CommandRelease(
const std::shared_ptr<VM>& vm, Actor&
self);
215 static void CommandDuplicate(
const std::shared_ptr<VM>& vm, Actor&
self);
216 static void CommandRemove(
const std::shared_ptr<VM>& vm, Actor&
self);
217 static void CommandLoadStaticAddress(
const std::shared_ptr<VM>& vm, Actor&
self);
218 static void CommandLoadGlobalAddress(
const std::shared_ptr<VM>& vm, Actor&
self);
219 static void CommandLoadFrameAddress(
const std::shared_ptr<VM>& vm, Actor&
self);
220 static void CommandLoadSelfAddress(
const std::shared_ptr<VM>& vm, Actor&
self);
221 static void CommandLoadInt8(
const std::shared_ptr<VM>& vm, Actor&
self);
222 static void CommandLoadInt16(
const std::shared_ptr<VM>& vm, Actor&
self);
223 static void CommandLoadInt32(
const std::shared_ptr<VM>& vm, Actor&
self);
224 static void CommandLoadFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
225 static void CommandLoadReference(
const std::shared_ptr<VM>& vm, Actor&
self);
226 static void CommandStoreInt8(
const std::shared_ptr<VM>& vm, Actor&
self);
227 static void CommandStoreInt16(
const std::shared_ptr<VM>& vm, Actor&
self);
228 static void CommandStoreInt32(
const std::shared_ptr<VM>& vm, Actor&
self);
229 static void CommandStoreFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
230 static void CommandStoreReference(
const std::shared_ptr<VM>& vm, Actor&
self);
231 static void CommandBranchEqual(
const std::shared_ptr<VM>& vm, Actor&
self);
232 static void CommandBranchNotEqual(
const std::shared_ptr<VM>& vm, Actor&
self);
233 static void CommandBranchAway(
const std::shared_ptr<VM>& vm, Actor&
self);
234 static void CommandBranchSubRoutine(
const std::shared_ptr<VM>& vm, Actor&
self);
235 static void CommandCall(
const std::shared_ptr<VM>& vm, Actor&
self);
236 static void CommandRequest(
const std::shared_ptr<VM>& vm, Actor&
self);
237 static void CommandRequestWaitStarting(
const std::shared_ptr<VM>& vm, Actor&
self);
238 static void CommandRequestWaitEnding(
const std::shared_ptr<VM>& vm, Actor&
self);
239 static void CommandDynamicRequest(
const std::shared_ptr<VM>& vm, Actor&
self);
240 static void CommandDynamicRequestWaitStarting(
const std::shared_ptr<VM>& vm, Actor&
self);
241 static void CommandDynamicRequestWaitEnded(
const std::shared_ptr<VM>& vm, Actor&
self);
242 static void CommandJoin(
const std::shared_ptr<VM>& vm, Actor&
self);
243 static void CommandComply(
const std::shared_ptr<VM>& vm, Actor&
self);
244 static void CommandRefuse(
const std::shared_ptr<VM>& vm, Actor&
self);
245 static void CommandLoadReturnAddress(
const std::shared_ptr<VM>& vm, Actor&
self);
246 static void CommandStoreReturnAddress(
const std::shared_ptr<VM>& vm, Actor&
self);
247 static void CommandReturnFromFunction(
const std::shared_ptr<VM>& vm, Actor&
self);
248 static void CommandReturnFromAction(
const std::shared_ptr<VM>& vm, Actor&
self);
249 static void CommandRollback(
const std::shared_ptr<VM>& vm, Actor&
self);
250 static void CommandAddInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
251 static void CommandAddFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
252 static void CommandDivideInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
253 static void CommandDivideFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
254 static void CommandMinusInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
255 static void CommandMinusFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
256 static void CommandModInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
257 static void CommandModFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
258 static void CommandMultiplyInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
259 static void CommandMultiplyFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
260 static void CommandSubtractInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
261 static void CommandSubtractFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
262 static void CommandAnd(
const std::shared_ptr<VM>& vm, Actor&
self);
263 static void CommandExclusiveOr(
const std::shared_ptr<VM>& vm, Actor&
self);
264 static void CommandLogicalAnd(
const std::shared_ptr<VM>& vm, Actor&
self);
265 static void CommandLogicalOr(
const std::shared_ptr<VM>& vm, Actor&
self);
266 static void CommandNot(
const std::shared_ptr<VM>& vm, Actor&
self);
267 static void CommandLogicalNot(
const std::shared_ptr<VM>& vm, Actor&
self);
268 static void CommandOr(
const std::shared_ptr<VM>& vm, Actor&
self);
269 static void CommandShiftLeft(
const std::shared_ptr<VM>& vm, Actor&
self);
270 static void CommandShiftRight(
const std::shared_ptr<VM>& vm, Actor&
self);
271 static void CommandCompareEqualInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
272 static void CommandCompareEqualFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
273 static void CommandCompareGreaterEqualInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
274 static void CommandCompareGreaterEqualFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
275 static void CommandCompareGreaterInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
276 static void CommandCompareGreaterFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
277 static void CommandCompareNotEqualInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
278 static void CommandCompareNotEqualFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
279 static void CommandCompareLessEqualInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
280 static void CommandCompareLessEqualFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
281 static void CommandCompareLessInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
282 static void CommandCompareLessFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
283 static void CommandIntegerToFloat(
const std::shared_ptr<VM>& vm, Actor&
self);
284 static void CommandFloatToInteger(
const std::shared_ptr<VM>& vm, Actor&
self);
285 static void CommandPushActor(
const std::shared_ptr<VM>& vm, Actor&
self);
286 static void CommandLoadData(
const std::shared_ptr<VM>& vm, Actor&
self);
287 static void CommandStoreData(
const std::shared_ptr<VM>& vm, Actor&
self);
288 static void CommandDuplicateData(
const std::shared_ptr<VM>& vm, Actor&
self);
289 static void CommandRemoveData(
const std::shared_ptr<VM>& vm, Actor&
self);
290 static void CommandCompareEqualData(
const std::shared_ptr<VM>& vm, Actor&
self);
291 static void CommandCompareGreaterEqualData(
const std::shared_ptr<VM>& vm, Actor&
self);
292 static void CommandCompareGreaterData(
const std::shared_ptr<VM>& vm, Actor&
self);
293 static void CommandCompareNotEqualData(
const std::shared_ptr<VM>& vm, Actor&
self);
294 static void CommandCompareLessEqualData(
const std::shared_ptr<VM>& vm, Actor&
self);
295 static void CommandCompareLessData(
const std::shared_ptr<VM>& vm, Actor&
self);
296 static void CommandPrint(
const std::shared_ptr<VM>& vm, Actor&
self);
300 #if MANA_BUILD_TARGET > MANA_BUILD_DEBUG
302 #define MANA_ASSERT_PARAMETER(P, I) { \
303 if(P->GetArgumentCount() != I) \
307 #define MANA_ASSERT_ILLIGAL_CALL_IN_INIT_ACTION(P) { \
308 if(P->GetVirtualMachine()->IsInInitAction()){ \
313 #define MANA_ASSERT_PARAMETER(P, I) \
314 if((P)->GetArgumentCount() != (I)){ \
315 MANA_PRINT({ "ERROR: ", (P)->GetName(), ": function ", (P)->GetFunctionName(), " number of arguments ", std::to_string((P)->GetArgumentCount()), " correct ", std::to_string(I), "\n" });\
319 #define MANA_ASSERT_CANT_CALL_IN_INIT_ACTION(P) \
320 if((P)->GetVirtualMachine()->IsInInitAction()){ \
321 MANA_PRINT({ "ERROR: ", (P)->GetName(), ": init action ", (P)->GetFunctionName()," can not call\n" });\
bool Run()
Definition: Actor.inl:31
const std::string_view & GetName()
Definition: Actor.inl:500
void RemoveRollbackEvent(const EventNameType eventName)
Definition: Actor.inl:762
int32_t GetInterruptPriority() const
Definition: Actor.inl:716
void SetReturnActor(const std::shared_ptr< Actor > &actor)
Definition: Actor.inl:591
void * GetUserPointer() const
Definition: Actor.inl:777
void SetUserData(const uintptr_t userData)
Definition: Actor.inl:772
void Again()
Definition: Actor.inl:679
bool IsRunning() const
Definition: Actor.inl:661
void SetReturnString(const char *string)
Definition: Actor.inl:585
void Repeat(const bool initialComplete)
Definition: Actor.inl:668
uintptr_t GetUserData() const
Definition: Actor.inl:767
void yield()
Definition: Actor.inl:700
void SetUserPointer(void *userPointer)
Definition: Actor.inl:782
void Stop()
Definition: Actor.inl:695
void Restart()
Definition: Actor.inl:488
bool SyncCall(const int32_t priority, const char *action, const std::shared_ptr< Actor > &sender)
Definition: Actor.inl:223
void SetSynchronized(const bool synchronized)
Definition: Actor.inl:729
void SetSynchronizedWithPriority(const int32_t priority, const bool synchronized)
Definition: Actor.inl:738
bool IsCommandRepeat() const
Definition: Actor.inl:653
int32_t GetParameterInteger(const int32_t value)
Definition: Actor.inl:536
void SetReturnFloat(const float value)
Definition: Actor.inl:579
bool Request(const int32_t priority, const char *action, const std::shared_ptr< Actor > &sender)
Definition: Actor.inl:253
float GetParameterFloat(const int32_t value)
Definition: Actor.inl:544
bool IsCommandInitialized() const
Definition: Actor.inl:645
Actor * GetParameterActor(const int32_t value)
Definition: Actor.inl:556
int32_t GetArgumentCountByAddress(const uint32_t address) const
Definition: Actor.inl:521
bool IsSynchronized() const
Definition: Actor.inl:721
Actor(const Actor &)=delete
int32_t GetArgumentSize(const uint32_t address)
Definition: Actor.inl:526
void SetReturnPointer(void *pointer)
Definition: Actor.inl:597
const char * GetParameterString(const int32_t value)
Definition: Actor.inl:550
bool HasReturnValue(const uint32_t address)
Definition: Actor.inl:531
void SetReturnInteger(const int32_t value)
Definition: Actor.inl:573
void SetReturnData(const void *pointer, const int32_t size)
Definition: Actor.inl:603
void * GetParameterPointer(const int32_t value)
Definition: Actor.inl:561
Actor(Actor &&) noexcept=delete
EventNameType AddRollbackEvent(const std::function< void(int32_t)> &function)
Definition: Actor.inl:757
void Rollback(const int32_t priority)
Definition: Actor.inl:358
void Refuse()
Definition: Actor.inl:711
std::shared_ptr< Actor > Clone() const
Definition: Actor.inl:21
bool AsyncCall(const int32_t priority, const char *action, const std::shared_ptr< Actor > &sender)
Definition: Actor.inl:238
void Accept()
Definition: Actor.inl:706
int32_t GetArgumentCount() const
Definition: Actor.inl:516
Stack & GetStack()
Definition: Actor.inl:787
std::shared_ptr< VM > GetVirtualMachine() const
Definition: Actor.inl:640
void * GetParameterAddress(const int32_t value)
Definition: Actor.inl:567
void Halt()
Definition: Actor.inl:685
uint32_t GetAction(const std::string_view &actionName) const
Definition: Actor.inl:505
void RemoveRequestEvent(const EventNameType eventName)
Definition: Actor.inl:752
EventNameType AddRequestEvent(const std::function< void(int32_t)> &function)
Definition: Actor.inl:747
int32_t(*)(const std::shared_ptr< Actor > &actor, void *parameter) Callback
request / rollbackコールバック
Definition: Actor.h:37
Definition: CodeBuffer.cpp:12
std::uint32_t address_t
Definition: Type.h:31
std::int32_t int_t
Definition: Type.h:29
float float_t
Definition: Type.h:28
uint32_t EventNameType
Definition: Event.h:15
Definition: Noncopyable.h:18