From e3d6794e2f985b553e54919a373615a5b03ce03a Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 12 Sep 2024 12:50:00 +0800 Subject: [PATCH] adds more tests for flexarray etc. (#60) * adds more tests for flexarray etc. * improve tests * adds `nifcache/` to .gitignore --- .gitignore | 3 +- tests/nifc/hello.expected.idx.nif | 39 +++++++++++++++-- tests/nifc/hello.nif | 69 ++++++++++++++++++++++++++++++- tests/tester.nim | 4 +- 4 files changed, 108 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index fea3ab9f..825f7c3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ nimcache/ nimblecache/ htmldocs/ -*.exe \ No newline at end of file +*.exe +nifcache/ \ No newline at end of file diff --git a/tests/nifc/hello.expected.idx.nif b/tests/nifc/hello.expected.idx.nif index b9c13fe1..32183d22 100644 --- a/tests/nifc/hello.expected.idx.nif +++ b/tests/nifc/hello.expected.idx.nif @@ -26,7 +26,40 @@ (kv a2 +27) (kv a3 +31) (kv a4 +25) - (kv printf.c +48) - (kv f.1 +24) - (kv main.c +60)) + (kv foo.c +36) + (kv foo2.c +85) + (kv x.c +32) + (kv MyObject.ptr.flexarray +105) + (kv a1 +47) + (kv a2 +27) + (kv a3 +31) + (kv a4 +25) + (kv MyObject.flexarray +49) + (kv a1 +43) + (kv a2 +27) + (kv a3 +31) + (kv a4 +25) + (kv MyObject.ptr +46) + (kv a1 +37) + (kv a2 +27) + (kv a3 +31) + (kv a4 +25) + (kv MyObject.aptr +40) + (kv a1 +38) + (kv a2 +27) + (kv a3 +31) + (kv a4 +25) + (kv MyObject.ptr.object +41) + (kv a1 +44) + (kv a2 +27) + (kv a3 +31) + (kv a4 +25) + (kv MyObject.my.sequence +44) + (kv len +46) + (kv p +26) + (kv MyObject.sequence.base +54) + (kv cap +49) + (kv data +28) + (kv main.c +47) + (kv x.c +42)) ) diff --git a/tests/nifc/hello.nif b/tests/nifc/hello.nif index 84b3f028..9d04f634 100644 --- a/tests/nifc/hello.nif +++ b/tests/nifc/hello.nif @@ -37,11 +37,76 @@ ) ) + (proc :foo.c . (void) . (stmts + (call printf.c "foo %s" "abc") + )) + + (nodecl (proc :foo2.c . (void) . (stmts + (var :x.c . (i +32 .) +12) + (call printf.c "foo %s" "abc") + (call printf.c "foo %d" x.c) + ))) + + (type :MyObject.ptr.flexarray . + (object . (fld :a1 . (i +32 atomic)) + (fld :a2 . (i +64 atomic)) + (fld :a3 . (bool .)) + (fld :a4 . (ptr MyObject.flexarray)) + ) + ) + + (type :MyObject.flexarray . + (object . (fld :a1 . (i +32 atomic)) + (fld :a2 . (i +64 atomic)) + (fld :a3 . (bool .)) + (fld :a4 . (flexarray (i +64 .))) + ) + ) + + (type :MyObject.ptr . + (object . (fld :a1 . (i +32 atomic)) + (fld :a2 . (i +64 atomic)) + (fld :a3 . (bool .)) + (fld :a4 . (ptr (i +64 .))) + ) + ) + + (type :MyObject.aptr . + (object . (fld :a1 . (i +32 atomic)) + (fld :a2 . (i +64 atomic)) + (fld :a3 . (bool .)) + (fld :a4 . (aptr (i +64 .))) + ) + ) + + (type :MyObject.ptr.object . + (object . (fld :a1 . (i +32 atomic)) + (fld :a2 . (i +64 atomic)) + (fld :a3 . (bool .)) + (fld :a4 . (ptr MyObject3.m .)) + ) + ) + + + (type :MyObject.my.sequence . + (object . + (fld :len . (i -1 .)) + (fld :p . (ptr MyObject.sequence.base .)) + ) + ) + + (type :MyObject.sequence.base . + (object . + (fld :cap . (i -1 .)) + (fld :data . (flexarray (i +64 .))) + )) - (nodecl (proc :printf.c (params (param :f.1 . (ptr FILE.c))) (void) (pragmas (varargs)) .)) - (proc :main.c . (i -1 +90) . (stmts + (proc :main.c . (i -1 atomic) . (stmts + (var :x.c . (i +32 .) +12) (call printf.c "hello %s" "abc") (call printf.c "hello %d" (suf +12 "i64")) + (call printf.c "hello %d" x.c) + (call foo.c) (ret +0) )) ) diff --git a/tests/tester.nim b/tests/tester.nim index 61d1573e..f8587bb1 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -223,6 +223,8 @@ proc testNifc(overwrite: bool) = let t1 = "tests/nifc/selectany/t1.nif" let t2 = "tests/nifc/selectany/t2.nif" let t3 = "tests/nifc/selectany/t3.nif" - exec ("src" / "nifc" / "nifc").addFileExt(ExeExt) & " c" & " " & t1 & " " & t2 & " " & t3 + exec ("src" / "nifc" / "nifc").addFileExt(ExeExt) & " c " & t1 & " " & t2 & " " & t3 + let hello = "tests/nifc/hello.nif" + exec ("src" / "nifc" / "nifc").addFileExt(ExeExt) & " c " & hello testNifc(overwrite)