UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMSuspension.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
7#include "VVMBytecode.h"
8#include "VVMCell.h"
10#include "VVMProcedure.h"
11#include <array>
12#include <type_traits>
13
14namespace Verse
15{
16struct FOp;
17struct VFailureContext;
18struct VProcedure;
19struct VTask;
20
21struct VSuspension : VCell
22{
24
28
29 // This field is only needed during cooking.
30#if WITH_EDITORONLY_DATA
31 TWriteBarrier<VPackage> CurrentPackage;
32#endif
33 // TODO: These fields are needed for CVarForceCompileFramework, but should otherwise be WITH_EDITORONLY_DATA.
36
38 {
39 VSuspension* Current = this;
40 while (Current->Next)
41 {
42 Current = Current->Next.Get();
43 }
44 return *Current;
45 }
46
47protected:
49};
50
51struct VBytecodeSuspension : public VSuspension
52{
55
56 template <typename Captures>
58 {
59 static_assert(std::is_same_v<Captures, std::decay_t<Captures>>);
60 std::byte* Allocation = std::is_trivially_destructible_v<Captures>
61 ? Context.AllocateFastCell(CapturesOffset<Captures>() + sizeof(Captures))
62 : Context.Allocate(FHeap::DestructorSpace, CapturesOffset<Captures>() + sizeof(Captures));
64 }
65
66 FOp* AwaitPC;
68 const EOpcode Opcode;
69 const uint32 BytecodeOffset;
70
71 template <typename Captures>
72 Captures& GetCaptures()
73 {
74 static_assert(std::is_same_v<Captures, std::decay_t<Captures>>);
76 }
77
78 template <typename TFunc>
79 void CaptureSwitch(const TFunc& Func);
80
81private:
82 template <typename Captures>
83 static size_t CapturesOffset()
84 {
85 return Align(sizeof(VBytecodeSuspension), alignof(Captures));
86 }
87
88 template <typename Captures>
93 , Opcode(PC->Opcode)
94 , BytecodeOffset(Procedure.BytecodeOffset(*PC))
95 {
96 static_assert(std::is_same_v<Captures, std::decay_t<Captures>>);
98 }
99
101};
102
103// This is used when you want to run a callback when a placeholder resolves its value.
104// The Args array is there to capture and mark the VValue arguments that the lambda
105// wants to use.
106struct VLambdaSuspension : public VSuspension
107{
110
112
114 {
115 return BitCast<TWriteBarrier<VValue>*>(BitCast<char*>(this) + ArgsOffset());
116 }
117
118 uint32 NumValues;
119 CallbackType Callback;
120
121 template <typename... Args>
122 static VLambdaSuspension& New(FAllocationContext Context, VFailureContext& FailureContext, VTask& Task, CallbackType Callback, Args&&... TheArgs)
123 {
124 return *new (Context.AllocateFastCell(AllocationSize(sizeof...(Args)))) VLambdaSuspension(Context, FailureContext, Task, Callback, std::forward<Args>(TheArgs)...);
125 }
126
127private:
128 static size_t ArgsOffset()
129 {
130 return Align(sizeof(VLambdaSuspension), alignof(TWriteBarrier<VValue>));
131 }
132
133 static size_t AllocationSize(uint32 NumValues)
134 {
135 return ArgsOffset() + NumValues * sizeof(TWriteBarrier<VValue>);
136 }
137
138 template <typename... ArgsType>
141 , NumValues(sizeof...(ArgsType))
142 , Callback(Callback)
143 {
144 new (Args()) TWriteBarrier<VValue>[] {
145 TWriteBarrier<VValue>(Context, std::forward<ArgsType>(TheArgs))...
146 };
147 }
148};
149
150} // namespace Verse
151#endif // WITH_VERSE_VM
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
constexpr T Align(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:18
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
T * New(FMemStackBase &Mem, int32 Count=1, int32 Align=DEFAULT_ALIGNMENT)
Definition MemStack.h:259
EObjectFlags
Definition ObjectMacros.h:552
uint32_t uint32
Definition binka_ue_file_header.h:6
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
Definition Archive.h:36