Skip to content

Commit

Permalink
added support for UE 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeioris committed Nov 13, 2024
1 parent 4fca4b8 commit 0e43e34
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion MathVM.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "20240424",
"VersionName": "20241123",
"FriendlyName": "MathVM",
"Description": "Math Expressions Evaluator",
"Category": "Other",
Expand Down
16 changes: 8 additions & 8 deletions Source/MathVM/Private/MathVMCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ bool FMathVMBase::Compile()
{
while (!OperatorStack.IsEmpty() && OperatorStack.Last()->TokenType == EMathVMTokenType::Operator && OperatorStack.Last()->Precedence <= Token.Precedence)
{
OutputQueue.Add(OperatorStack.Pop(false));
OutputQueue.Add(MATHVM_POP(OperatorStack));
}
OperatorStack.Add(&Token);
}
else if (Token.TokenType == EMathVMTokenType::Comma)
{
while (!OperatorStack.IsEmpty() && OperatorStack.Last()->TokenType != EMathVMTokenType::OpenParenthesis)
{
OutputQueue.Add(OperatorStack.Pop(false));
OutputQueue.Add(MATHVM_POP(OperatorStack));
}

if (FunctionHasFirstArgStack.IsEmpty() || !FunctionHasFirstArgStack.Last())
Expand Down Expand Up @@ -90,13 +90,13 @@ bool FMathVMBase::Compile()
{
while (!OperatorStack.IsEmpty() && OperatorStack.Last()->TokenType != EMathVMTokenType::OpenParenthesis)
{
OutputQueue.Add(OperatorStack.Pop(false));
OutputQueue.Add(MATHVM_POP(OperatorStack));
}
if (OperatorStack.IsEmpty() || OperatorStack.Last()->TokenType != EMathVMTokenType::OpenParenthesis)
{
return SetError("Expected open parenthesis");
}
OperatorStack.Pop(false);
MATHVM_POP(OperatorStack);

if (!OperatorStack.IsEmpty())
{
Expand All @@ -105,13 +105,13 @@ bool FMathVMBase::Compile()
// this is basically the only case the compiler needs a const_cast
FMathVMToken* FunctionToken = const_cast<FMathVMToken*>(OperatorStack.Last());

FunctionToken->DetectedNumArgs = FunctionsArgsStack.Pop(false) + (FunctionHasFirstArgStack.Pop() ? 1 : 0);
FunctionToken->DetectedNumArgs = MATHVM_POP(FunctionsArgsStack) + (FunctionHasFirstArgStack.Pop() ? 1 : 0);

if (FunctionToken->NumArgs >= 0 && FunctionToken->DetectedNumArgs != FunctionToken->NumArgs)
{
return SetError(FString::Printf(TEXT("Function %s expects %d argument%s (detected %d)"), *(FunctionToken->Value), FunctionToken->NumArgs, FunctionToken->NumArgs == 1 ? TEXT("") : TEXT("s"), FunctionToken->DetectedNumArgs));
}
OutputQueue.Add(OperatorStack.Pop(false));
OutputQueue.Add(MATHVM_POP(OperatorStack));
}
}
}
Expand All @@ -123,7 +123,7 @@ bool FMathVMBase::Compile()
{
return SetError("Mismatched parenthesis");
}
OutputQueue.Add(OperatorStack.Pop(false));
OutputQueue.Add(MATHVM_POP(OperatorStack));
}
Statements.Add(OutputQueue);
OutputQueue.Empty();
Expand All @@ -139,7 +139,7 @@ bool FMathVMBase::Compile()
{
return SetError("Mismatched parenthesis");
}
OutputQueue.Add(OperatorStack.Pop(false));
OutputQueue.Add(MATHVM_POP(OperatorStack));
}
Statements.Add(OutputQueue);

Expand Down
6 changes: 3 additions & 3 deletions Source/MathVM/Private/MathVMRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool FMathVMBase::Execute(TMap<FString, double>& LocalVariables, const int32 Pop
return false;
}

const FMathVMToken* LastToken = CallContext.Stack.Pop(false);
const FMathVMToken* LastToken = MATHVM_POP(CallContext.Stack);

if (LastToken->TokenType == EMathVMTokenType::Number)
{
Expand Down Expand Up @@ -165,7 +165,7 @@ bool FMathVMCallContext::PopArgument(double& Value)
return false;
}

const FMathVMToken* Token = Stack.Pop(false);
const FMathVMToken* Token = MATHVM_POP(Stack);

if (Token->TokenType == EMathVMTokenType::Variable)
{
Expand Down Expand Up @@ -208,7 +208,7 @@ bool FMathVMCallContext::PopName(FString& Name)
return false;
}

const FMathVMToken* Token = Stack.Pop(false);
const FMathVMToken* Token = MATHVM_POP(Stack);

if (Token->TokenType == EMathVMTokenType::Variable)
{
Expand Down
6 changes: 6 additions & 0 deletions Source/MathVM/Public/MathVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#define MATHVM_RETURN(x) return CallContext.PushResult(x)
#define MATHVM_ERROR(x) return CallContext.SetError(x)

#if ENGINE_MINOR_VERSION >= 5
#define MATHVM_POP(x) x.Pop(EAllowShrinking::No)
#else
#define MATHVM_POP(x) x.Pop(false)
#endif

enum class EMathVMTokenType : uint8
{
Number,
Expand Down

0 comments on commit 0e43e34

Please sign in to comment.