From 19cf887ad12f5ab32a3b8a98b690cbc2ab347664 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 19 Jan 2018 19:48:55 +0100 Subject: [PATCH] - fixed: Dynamic arrays for object pointers need different treatment than arrays for regular pointers, because they require GC::WriteBarrier to be called. --- src/scripting/backend/dynarrays.cpp | 108 ++++++++++++++++++++++++++++ src/scripting/types.cpp | 5 +- wadsrc/static/zscript/dynarrays.txt | 19 +++++ 3 files changed, 131 insertions(+), 1 deletion(-) diff --git a/src/scripting/backend/dynarrays.cpp b/src/scripting/backend/dynarrays.cpp index c12e602a08..56331442fa 100644 --- a/src/scripting/backend/dynarrays.cpp +++ b/src/scripting/backend/dynarrays.cpp @@ -51,6 +51,7 @@ typedef TArray FDynArray_I32; typedef TArray FDynArray_F32; typedef TArray FDynArray_F64; typedef TArray FDynArray_Ptr; +typedef TArray FDynArray_Obj; typedef TArray FDynArray_String; //----------------------------------------------------- @@ -672,6 +673,112 @@ DEFINE_ACTION_FUNCTION(FDynArray_Ptr, Clear) } +//----------------------------------------------------- +// +// Object array +// +//----------------------------------------------------- + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Copy) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + PARAM_POINTER(other, FDynArray_Obj); + *self = *other; + return 0; +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Move) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + PARAM_POINTER(other, FDynArray_Obj); + *self = std::move(*other); + return 0; +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Find) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + PARAM_OBJECT(val, DObject); + ACTION_RETURN_INT(self->Find(val)); +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Push) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + PARAM_OBJECT(val, DObject); + GC::WriteBarrier(val); + ACTION_RETURN_INT(self->Push(val)); +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Pop) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + ACTION_RETURN_BOOL(self->Pop()); +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Delete) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + PARAM_INT(index); + PARAM_INT_DEF(count); + self->Delete(index, count); + return 0; +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Insert) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + PARAM_INT(index); + PARAM_OBJECT(val, DObject); + GC::WriteBarrier(val); + self->Insert(index, val); + return 0; +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, ShrinkToFit) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + self->ShrinkToFit(); + return 0; +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Grow) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + PARAM_INT(count); + self->Grow(count); + return 0; +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Resize) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + PARAM_INT(count); + self->Resize(count); + return 0; +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Reserve) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + PARAM_INT(count); + ACTION_RETURN_INT(self->Reserve(count)); +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Max) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + ACTION_RETURN_INT(self->Max()); +} + +DEFINE_ACTION_FUNCTION(FDynArray_Obj, Clear) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + self->Clear(); + return 0; +} + + //----------------------------------------------------- // // String array @@ -781,4 +888,5 @@ DEFINE_FIELD_NAMED_X(DynArray_I32, FArray, Count, Size) DEFINE_FIELD_NAMED_X(DynArray_F32, FArray, Count, Size) DEFINE_FIELD_NAMED_X(DynArray_F64, FArray, Count, Size) DEFINE_FIELD_NAMED_X(DynArray_Ptr, FArray, Count, Size) +DEFINE_FIELD_NAMED_X(DynArray_Obj, FArray, Count, Size) DEFINE_FIELD_NAMED_X(DynArray_String, FArray, Count, Size) diff --git a/src/scripting/types.cpp b/src/scripting/types.cpp index 91ceb9077a..5059834d48 100644 --- a/src/scripting/types.cpp +++ b/src/scripting/types.cpp @@ -2050,7 +2050,10 @@ PDynArray *NewDynArray(PType *type) break; case REGT_POINTER: - backingname = "DynArray_Ptr"; + if (type->isObjectPointer()) + backingname = "DynArray_Obj"; + else + backingname = "DynArray_Ptr"; break; default: diff --git a/wadsrc/static/zscript/dynarrays.txt b/wadsrc/static/zscript/dynarrays.txt index 088e3cc41c..df10b70b2c 100644 --- a/wadsrc/static/zscript/dynarrays.txt +++ b/wadsrc/static/zscript/dynarrays.txt @@ -115,6 +115,25 @@ struct DynArray_Ptr native native void Clear (); } +struct DynArray_Obj native +{ + native readonly uint Size; + + native void Copy(DynArray_Obj other); + native void Move(DynArray_Obj other); + native uint Find(Object item) const; + native uint Push (Object item); + native bool Pop (); + native void Delete (uint index, int deletecount = 1); + native void Insert (uint index, Object item); + native void ShrinkToFit (); + native void Grow (uint amount); + native void Resize (uint amount); + native uint Reserve (uint amount); + native uint Max () const; + native void Clear (); +} + struct DynArray_String native { native readonly uint Size;