diff --git a/source/common/scripting/backend/codegen.cpp b/source/common/scripting/backend/codegen.cpp index 1c9209c58..0ec83f20a 100644 --- a/source/common/scripting/backend/codegen.cpp +++ b/source/common/scripting/backend/codegen.cpp @@ -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; } diff --git a/source/common/scripting/core/dynarrays.cpp b/source/common/scripting/core/dynarrays.cpp index 16bb57ca8..eebb97da8 100644 --- a/source/common/scripting/core/dynarrays.cpp +++ b/source/common/scripting/core/dynarrays.cpp @@ -121,6 +121,17 @@ template unsigned int ArrayReserve(T *self, int amount) return self->Reserve(amount); } +template<> unsigned int ArrayReserve(TArray *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 int ArrayMax(T *self) { return self->Max(); @@ -908,7 +919,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Reserve, ArrayReserveReserve(count)); + ACTION_RETURN_INT(ArrayReserve(self, count)); } DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Max, ArrayMax) diff --git a/source/common/scripting/core/types.h b/source/common/scripting/core/types.h index b35047525..0d6c6546e 100644 --- a/source/common/scripting/core/types.h +++ b/source/common/scripting/core/types.h @@ -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(); diff --git a/source/common/scripting/frontend/ast.cpp b/source/common/scripting/frontend/ast.cpp index ae198dc84..cb29457e4 100644 --- a/source/common/scripting/frontend/ast.cpp +++ b/source/common/scripting/frontend/ast.cpp @@ -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) diff --git a/source/common/scripting/frontend/zcc_compile.cpp b/source/common/scripting/frontend/zcc_compile.cpp index 5c73fc1cc..0bc337bde 100644 --- a/source/common/scripting/frontend/zcc_compile.cpp +++ b/source/common/scripting/frontend/zcc_compile.cpp @@ -1476,8 +1476,12 @@ bool ZCCCompiler::CompileFields(PContainerType *type, TArrayNames; 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, TArraySymbols.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, TArrayNames); Fields.Delete(0); } + + if (type != nullptr) + { + type->SizeKnown = Fields.Size() == 0; + } + return Fields.Size() == 0; } diff --git a/source/common/scripting/jit/jit.cpp b/source/common/scripting/jit/jit.cpp index 18ccb9246..6d141e652 100644 --- a/source/common/scripting/jit/jit.cpp +++ b/source/common/scripting/jit/jit.cpp @@ -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(PopFullVMFrame); popFrame->setArg(0, stack); diff --git a/source/common/scripting/jit/jit_flow.cpp b/source/common/scripting/jit/jit_flow.cpp index 5db91818a..8439481cf 100644 --- a/source/common/scripting/jit/jit_flow.cpp +++ b/source/common/scripting/jit/jit_flow.cpp @@ -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 { diff --git a/source/common/scripting/vm/vmexec.h b/source/common/scripting/vm/vmexec.h index 154cac29e..76e7596e7 100644 --- a/source/common/scripting/vm/vmexec.h +++ b/source/common/scripting/vm/vmexec.h @@ -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) diff --git a/source/common/scripting/vm/vmframe.cpp b/source/common/scripting/vm/vmframe.cpp index 7c2a63b1f..ff193320f 100644 --- a/source/common/scripting/vm/vmframe.cpp +++ b/source/common/scripting/vm/vmframe.cpp @@ -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.");