- updated VM from GZDoom.

Just to be up to date.
This commit is contained in:
Christoph Oelckers 2020-09-27 10:47:11 +02:00
parent 0314cdec55
commit cb49bcb96d
9 changed files with 60 additions and 9 deletions

View file

@ -4282,13 +4282,13 @@ FxExpression *FxBinaryLogical::Resolve(FCompileContext& ctx)
{
if (b_left==0 || b_right==0)
{
FxExpression *x = new FxConstant(true, ScriptPosition);
FxExpression *x = new FxConstant(false, ScriptPosition);
delete this;
return x;
}
else if (b_left==1 && b_right==1)
{
FxExpression *x = new FxConstant(false, ScriptPosition);
FxExpression *x = new FxConstant(true, ScriptPosition);
delete this;
return x;
}

View file

@ -121,6 +121,17 @@ template<class T> unsigned int ArrayReserve(T *self, int amount)
return self->Reserve(amount);
}
template<> unsigned int ArrayReserve(TArray<DObject*> *self, int amount)
{
const unsigned int oldSize = self->Reserve(amount);
const unsigned int fillCount = self->Size() - oldSize;
if (fillCount > 0)
memset(&(*self)[oldSize], 0, sizeof(DObject*) * fillCount);
return oldSize;
}
template<class T> int ArrayMax(T *self)
{
return self->Max();
@ -908,7 +919,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Reserve, ArrayReserve<FDynArray_Obj
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_INT(count);
ACTION_RETURN_INT(self->Reserve(count));
ACTION_RETURN_INT(ArrayReserve(self, count));
}
DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Max, ArrayMax<FDynArray_Obj>)

View file

@ -101,6 +101,7 @@ public:
VersionInfo mVersion = { 0,0,0 };
uint8_t loadOp, storeOp, moveOp, RegType, RegCount;
EScopeFlags ScopeFlags = (EScopeFlags)0;
bool SizeKnown = true;
PType(unsigned int size = 1, unsigned int align = 1);
virtual ~PType();

View file

@ -913,6 +913,25 @@ static void PrintPropertyStmt(FLispString &out, ZCC_TreeNode *node)
out.Close();
}
static void PrintMixinDef(FLispString &out, ZCC_TreeNode *node)
{
ZCC_MixinDef *mdnode = (ZCC_MixinDef *)node;
out.Break();
out.Open("mixin-def");
out.AddName(mdnode->NodeName);
PrintNodes(out, mdnode->Body);
out.Close();
}
static void PrintMixinStmt(FLispString &out, ZCC_TreeNode *node)
{
ZCC_MixinStmt *msnode = (ZCC_MixinStmt *)node;
out.Break();
out.Open("mixin-stmt");
out.AddName(msnode->MixinName);
out.Close();
}
void (* const TreeNodePrinter[NUM_AST_NODE_TYPES])(FLispString &, ZCC_TreeNode *) =
{
PrintIdentifier,
@ -972,6 +991,8 @@ void (* const TreeNodePrinter[NUM_AST_NODE_TYPES])(FLispString &, ZCC_TreeNode *
PrintStaticArrayState,
PrintProperty,
PrintFlagDef,
PrintMixinDef,
PrintMixinStmt,
};
FString ZCC_PrintAST(ZCC_TreeNode *root)

View file

@ -1476,8 +1476,12 @@ bool ZCCCompiler::CompileFields(PContainerType *type, TArray<ZCC_VarDeclarator *
auto name = field->Names;
do
{
if (fieldtype->Size == 0 && !(varflags & VARF_Native)) // Size not known yet.
if ((fieldtype->Size == 0 || !fieldtype->SizeKnown) && !(varflags & VARF_Native)) // Size not known yet.
{
if (type != nullptr)
{
type->SizeKnown = false;
}
return false;
}
@ -1532,6 +1536,10 @@ bool ZCCCompiler::CompileFields(PContainerType *type, TArray<ZCC_VarDeclarator *
if (OutNamespace->Symbols.AddSymbol(f) == nullptr)
{ // name is already in use
if (type != nullptr)
{
type->SizeKnown = false;
}
f->Destroy();
return false;
}
@ -1565,6 +1573,12 @@ bool ZCCCompiler::CompileFields(PContainerType *type, TArray<ZCC_VarDeclarator *
} while (name != field->Names);
Fields.Delete(0);
}
if (type != nullptr)
{
type->SizeKnown = Fields.Size() == 0;
}
return Fields.Size() == 0;
}

View file

@ -390,7 +390,7 @@ static void PopFullVMFrame(VMFrameStack *stack)
void JitCompiler::EmitPopFrame()
{
if (sfunc->SpecialInits.Size() != 0 || sfunc->NumRegS != 0)
if (sfunc->SpecialInits.Size() != 0 || sfunc->NumRegS != 0 || sfunc->ExtraSpace != 0)
{
auto popFrame = CreateCall<void, VMFrameStack *>(PopFullVMFrame);
popFrame->setArg(0, stack);

View file

@ -310,7 +310,7 @@ void JitCompiler::ThrowArrayOutOfBounds(int index, int size)
{
if (index >= size)
{
ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Max.index = %u, current index = %u\n", size, index);
ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Size = %u, current index = %u\n", size, index);
}
else
{

View file

@ -806,7 +806,7 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
OP(BOUND):
if (reg.d[a] >= BC)
{
ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Max.index = %u, current index = %u\n", BC, reg.d[a]);
ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Size = %u, current index = %u\n", BC, reg.d[a]);
return 0;
}
else if (reg.d[a] < 0)
@ -820,7 +820,7 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
ASSERTKD(BC);
if (reg.d[a] >= konstd[BC])
{
ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Max.index = %u, current index = %u\n", konstd[BC], reg.d[a]);
ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Size = %u, current index = %u\n", konstd[BC], reg.d[a]);
return 0;
}
else if (reg.d[a] < 0)
@ -834,7 +834,7 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
ASSERTD(B);
if (reg.d[a] >= reg.d[B])
{
ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Max.index = %u, current index = %u\n", reg.d[B], reg.d[a]);
ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Size = %u, current index = %u\n", reg.d[B], reg.d[a]);
return 0;
}
else if (reg.d[a] < 0)

View file

@ -45,7 +45,11 @@
#include "version.h"
#ifdef HAVE_VM_JIT
#ifdef __DragonFly__
CUSTOM_CVAR(Bool, vm_jit, false, CVAR_NOINITCALL)
#else
CUSTOM_CVAR(Bool, vm_jit, true, CVAR_NOINITCALL)
#endif
{
Printf("You must restart " GAMENAME " for this change to take effect.\n");
Printf("This cvar is currently not saved. You must specify it on the command line.");