UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMValueInline.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
10#include "VerseVM/VVMFalse.h"
11#include "VerseVM/VVMFloat.h"
12#include "VerseVM/VVMInt.h"
13#include "VerseVM/VVMOpResult.h"
17#include "VerseVM/VVMValue.h"
18#include "VerseVM/VVMVerse.h"
19
20namespace Verse
21{
22V_FORCEINLINE VValue VRestValue::Get(FAllocationContext Context)
23{
24 if (UNLIKELY(Value.Get().IsRoot()))
25 {
26 return GetSlow(Context);
27 }
28 return Value.Get().Follow();
29}
30
31V_FORCEINLINE VValue VRestValue::GetTransactionally(FAllocationContext Context)
32{
33 if (UNLIKELY(Value.Get().IsRoot()))
34 {
36 }
37 return Value.Get().Follow();
38}
39
40inline bool VRestValue::operator==(const VRestValue& Other) const
41{
42 if (Value.Get().IsRoot() && Other.Value.Get().IsRoot())
43 {
44 return this == &Other;
45 }
46 return Value.Get() == Other.Value.Get();
47}
48
49inline VValue::VValue(VCell& Cell)
50 : Cell(&Cell)
51{
54}
55
56inline VValue::VValue(UObject* Object)
57 : EncodedBits(BitCast<uint64>(Object) | UObjectTag)
58{
59 checkSlow(IsUObject());
60}
61
62inline bool VValue::IsInt() const
63{
64 return IsInt32() || IsCellOfType<VHeapInt>();
65}
66
67inline VInt VValue::AsInt() const
68{
69 return VInt(*this);
70}
71
72inline bool VValue::IsUint32() const
73{
74 return IsInt() && AsInt().IsUint32();
75}
76
77inline uint32 VValue::AsUint32() const
78{
79 return AsInt().AsUint32();
80}
81
82inline VValue VValue::FromBool(bool Bool)
83{
84 return Bool ? VValue(GlobalTrue()) : VValue(GlobalFalse());
85}
86
87V_FORCEINLINE VValue VValue::Follow() const
88{
89 checkSlow(!IsRoot());
91 {
92 return AsPlaceholder().Follow();
93 }
94 return *this;
95}
96
97inline VPlaceholder& VValue::GetRootPlaceholder()
98{
99 return AsPlaceholder().Follow().AsPlaceholder();
100}
101
102inline void VValue::EnqueueSuspension(FAccessContext Context, VSuspension& Suspension)
103{
104 GetRootPlaceholder().EnqueueSuspension(Context, Suspension);
105}
106
107inline bool VValue::IsLogic() const
108{
109 return Cell == GlobalFalsePtr.Get() || Cell == GlobalTruePtr.Get();
110}
111
112inline bool VValue::AsBool() const
113{
114 check(IsLogic());
115 return Cell == GlobalTruePtr.Get();
116}
117
118inline bool VValue::IsEnumerator() const
119{
121}
122
123template <typename ObjectType>
124bool VValue::IsCellOfType() const
125{
126 return IsCell() && AsCell().IsA<ObjectType>();
127}
128
129template <typename ObjectType>
130ObjectType& VValue::StaticCast() const
131{
132 return AsCell().StaticCast<ObjectType>();
133}
134
135template <typename ObjectType>
136ObjectType* VValue::DynamicCast() const
137{
138 return IsCell() ? AsCell().DynamicCast<ObjectType>() : nullptr;
139}
140
141inline uint32 GetTypeHash(VValue Value)
142{
143 V_DIE_IF(Value.IsPlaceholder() || Value.IsUninitialized());
144 if (Value.IsFloat())
145 {
146 const Verse::VFloat ValueAsFloat = Value.AsFloat();
147 // Normalize any input NaN to a consistent standard for a "pure" NaN form.
148 if (ValueAsFloat.IsNaN())
149 {
150 return ::GetTypeHash(VFloat::NaN().AsDouble());
151 }
152 // Handles -0 VS +0 representations; just normalizes it to +0 if necessary.
153 // `AsDouble` calls `NormalizeSignedZero`.
154 return ::GetTypeHash(ValueAsFloat.AsDouble());
155 }
156 else if (Value.IsInt())
157 {
158 return GetTypeHash(Value.AsInt());
159 }
160 else if (Value.IsLogic())
161 {
162 return Value.AsBool() ? PointerHash(Verse::GlobalTruePtr.Get()) : PointerHash(Verse::GlobalFalsePtr.Get());
163 }
164 else if (Value.IsCell())
165 {
166 return GetTypeHash(Value.AsCell());
167 }
168 else if (Value.IsUObject())
169 {
170 return ::GetTypeHash(Value.AsUObject());
171 }
172 else if (Value.IsChar())
173 {
174 return ::GetTypeHash(Value.AsChar());
175 }
176 else if (Value.IsChar32())
177 {
178 return ::GetTypeHash(Value.AsChar32());
179 }
180 else
181 {
183 }
184}
185
186inline uint32 GetTypeHash(const VPlaceholder& Placeholder)
187{
188 // We're `const_cast`-ing here because `Follow` is non-const for the case where
189 // eventually we want to do path compression on the `VValue` within. In that case, the
190 // value would have to be modified since the underlying pointers would be re-pointed.
191 return GetTypeHash(const_cast<VPlaceholder&>(Placeholder).Follow());
192}
193
195{
196 return GetTypeHash(RestValue.Value.Get());
197}
198
199inline VValue VValue::Melt(FAllocationContext Context, VValue Value)
200{
201 if (Value.IsCell() && Value.AsCell().IsDeeplyMutable())
202 {
203 return Value.AsCell().Melt(Context);
204 }
205 return Value;
206}
207
208inline FOpResult VValue::Freeze(FAllocationContext Context, VValue Value, VTask* Task, FOp* AwaitPC)
209{
210 if (Value.IsPlaceholder())
211 {
212 V_DIE("Freezing does not support non-concrete values!");
213 }
214 else if (Value.IsCell() && Value.AsCell().IsDeeplyMutable())
215 {
216 return Value.AsCell().Freeze(Context, Task, AwaitPC);
217 }
219}
220
221} // namespace Verse
222#endif // WITH_VERSE_VM
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
#define UNLIKELY(x)
Definition Platform.h:857
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
ToType BitCast(const FromType &From)
Definition TypeCompatibleBytes.h:167
uint32 PointerHash(const void *Key)
Definition TypeHash.h:91
#define VERSE_UNREACHABLE()
Definition VVMUnreachable.h:8
#define V_FORCEINLINE
Definition VVMVerse.h:30
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Object.h:95
uint32 GetTypeHash(const FKey &Key)
Definition BlackboardKey.h:35
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
Definition Archive.h:36
Definition VVMFloat.h:22