Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit test for multi-push functionality in array #1441

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/test/unit_tests/array.das
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def test:bool
testIntArray()
testConstInArray()
testInterop()
testMultiPush()
return true

// this test bellow is only here to make sure AOT compiles and runs for array<blah const>
Expand All @@ -160,3 +161,29 @@ def testConstInArray
var b : Foo const[10]
testAccept(a, b)

[sideeffects]
def testMultiPush()
var a : array<Foo>
var b : array<Foo>
push(b, a)
verify(length(a)==0)
verify(length(b)==0)

a <- [Foo(bar=1), Foo(bar=2)]
push(b, a)
verify(length(a)==2)
verify(length(b)==2)
verify(a[0].bar==1)
verify(a[1].bar==2)
verify(b[0].bar==1)
verify(b[1].bar==2)

var c = fixed_array(Foo(bar=3))
push(b, c)
verify(length(b)==3)
verify(b[2].bar==3)
verify(c[0].bar==3)

push_clone(b, c)
verify(length(b)==4)
verify(b[3].bar==3)
94 changes: 88 additions & 6 deletions src/builtin/builtin.das
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,20 @@ def push(var Arr:array<auto(numT)>;var value:numT-# ==const)
concept_assert(false,"can't push value, which can't be copied")

[unused_argument(Arr, value)]
def push(var Arr:array<auto(numT)>; varr:array<numT>-#)
def push(var Arr:array<auto(numT)>; varr:array<numT-#> ==const)
static_if typeinfo(can_copy type<numT>)
static_if typeinfo(need_lock_check type<numT>)
_builtin_verify_locks(Arr)
static_if typeinfo(can_clone_from_const varr[0])
for t in varr
Arr[__builtin_array_push_back(Arr,typeinfo(sizeof Arr[0]))] = t
else
concept_assert(false,"can't push value, which can't be cloned from const")
else
concept_assert(false,"can't push value, which can't be copied")

[unused_argument(Arr, value)]
def push(var Arr:array<auto(numT)>; var varr:array<numT-#> ==const)
static_if typeinfo(can_copy type<numT>)
static_if typeinfo(need_lock_check type<numT>)
_builtin_verify_locks(Arr)
Expand All @@ -161,7 +174,22 @@ def push(var Arr:array<auto(numT)>; varr:numT[]-#)
concept_assert(false,"can't push value, which can't be copied")

[unused_argument(Arr, value)]
def push(var Arr:array<auto(numT)[]>; varr:numT[]-#)
def push(var Arr:array<auto(numT)[]>; varr:numT[]-# ==const)
static_if typeinfo(can_copy type<numT>)
static_if typeinfo(sizeof Arr[0])==typeinfo(sizeof varr)
static_if typeinfo(need_lock_check type<numT>)
_builtin_verify_locks(Arr)
static_if typeinfo(can_clone_from_const varr)
Arr[__builtin_array_push_back(Arr,typeinfo(sizeof Arr[0]))] = varr
else
concept_assert(false,"can't push array of different size")
else
concept_assert(false,"can't push array of different size")
else
concept_assert(false,"can't push value, which can't be copied")

[unused_argument(Arr, value)]
def push(var Arr:array<auto(numT)[]>; var varr:numT[]-# ==const)
static_if typeinfo(can_copy type<numT>)
static_if typeinfo(sizeof Arr[0])==typeinfo(sizeof varr)
static_if typeinfo(need_lock_check type<numT>)
Expand Down Expand Up @@ -212,15 +240,29 @@ def emplace(var Arr:array<auto(numT)[]>;var value:numT[]-#)
else
concept_assert(false,"can't emplace value, which can't be moved")

def push_clone(var Arr:array<auto(numT)>;value:numT|#;at:int)
[unused_argument(Arr, value, at)]
def push_clone(var Arr:array<auto(numT)>;value:numT ==const|#;at:int)
static_if typeinfo(can_clone value)
static_if typeinfo(need_lock_check type<numT>)
_builtin_verify_locks(Arr)
static_if typeinfo(can_clone_from_const value)
Arr[__builtin_array_push_zero(Arr,at,typeinfo(sizeof Arr[0]))] := value
else
concept_assert(false,"can't push-clone value, which can't be cloned from const")
else
concept_assert(false,"can't push-clone value, which can't be cloned")

[unused_argument(Arr, value, at)]
def push_clone(var Arr:array<auto(numT)>;var value:numT ==const|#;at:int)
static_if typeinfo(can_clone value)
static_if typeinfo(need_lock_check type<numT>)
_builtin_verify_locks(Arr)
Arr[__builtin_array_push_zero(Arr,at,typeinfo(sizeof Arr[0]))] := value
else
concept_assert(false,"can't push-clone value, which can't be cloned")

def push_clone(var Arr:array<auto(numT)>;value:numT|#)
[unused_argument(Arr, value)]
def push_clone(var Arr:array<auto(numT)>;value:numT ==const|#)
static_if typeinfo(can_clone value)
static_if typeinfo(need_lock_check type<numT>)
_builtin_verify_locks(Arr)
Expand All @@ -231,7 +273,30 @@ def push_clone(var Arr:array<auto(numT)>;value:numT|#)
else
concept_assert(false,"can't push-clone value, which can't be cloned")

def push_clone(var Arr:array<auto(numT)>; varr:numT[])
[unused_argument(Arr, value)]
def push_clone(var Arr:array<auto(numT)>;var value:numT ==const|#)
static_if typeinfo(can_clone value)
static_if typeinfo(need_lock_check type<numT>)
_builtin_verify_locks(Arr)
Arr[__builtin_array_push_back_zero(Arr,typeinfo(sizeof Arr[0]))] := value
else
concept_assert(false,"can't push-clone value, which can't be cloned")

[unused_argument(Arr, value)]
def push_clone(var Arr:array<auto(numT)>; varr:numT[] ==const)
static_if typeinfo(can_clone type<numT>)
static_if typeinfo(need_lock_check type<numT>)
_builtin_verify_locks(Arr)
static_if typeinfo(can_clone_from_const varr[0])
for t in varr
Arr[__builtin_array_push_back(Arr,typeinfo(sizeof Arr[0]))] := t
else
concept_assert(false,"can't push-clone value, which can't be cloned from const")
else
concept_assert(false,"can't push_clone value, which can't be cloned")

[unused_argument(Arr, value)]
def push_clone(var Arr:array<auto(numT)>; var varr:numT[] ==const)
static_if typeinfo(can_clone type<numT>)
static_if typeinfo(need_lock_check type<numT>)
_builtin_verify_locks(Arr)
Expand All @@ -240,7 +305,24 @@ def push_clone(var Arr:array<auto(numT)>; varr:numT[])
else
concept_assert(false,"can't push_clone value, which can't be cloned")

def push_clone(var Arr:array<auto(numT)[]>; varr:numT[])
[unused_argument(Arr, value)]
def push_clone(var Arr:array<auto(numT)[]>; varr:numT[] ==const)
static_if typeinfo(can_copy type<numT>)
static_if typeinfo(sizeof Arr[0])==typeinfo(sizeof varr)
static_if typeinfo(need_lock_check type<numT>)
_builtin_verify_locks(Arr)
if typeinfo(can_clone_from_const varr)
for t in varr
Arr[__builtin_array_push_back(Arr,typeinfo(sizeof Arr[0]))] := t
else
concept_assert(false,"can't push-clone value, which can't be cloned from const")
else
concept_assert(false,"can't push_clone array of different size")
else
concept_assert(false,"can't push value, which can't be cloned")

[unused_argument(Arr, value)]
def push_clone(var Arr:array<auto(numT)[]>; var varr:numT[])
static_if typeinfo(can_copy type<numT>)
static_if typeinfo(sizeof Arr[0])==typeinfo(sizeof varr)
static_if typeinfo(need_lock_check type<numT>)
Expand Down
Loading
Loading