From 13f43cadeb9e4284ec85837f2e7aa26aacb934f1 Mon Sep 17 00:00:00 2001 From: Mid <> Date: Sat, 3 May 2025 10:03:51 +0300 Subject: [PATCH] More tests --- tests/Exporter.nct | 5 +++++ tests/GenericStruct.nct | 44 ++++++++++++++++++++++++++++++++++++++ tests/Importer.nct | 3 +++ tests/UDPEcho.nct | 43 +++++++++++++++++++++++++++++++++++++ tests/lvl1localrecord.nct | 16 ++++++++++++++ tests/lvl1symbolrecord.nct | 17 +++++++++++++++ tests/lvl2localrecord.nct | 16 ++++++++++++++ tests/lvl2symbolrecord.nct | 19 ++++++++++++++++ 8 files changed, 163 insertions(+) create mode 100644 tests/Exporter.nct create mode 100644 tests/GenericStruct.nct create mode 100644 tests/Importer.nct create mode 100644 tests/UDPEcho.nct create mode 100644 tests/lvl1localrecord.nct create mode 100644 tests/lvl1symbolrecord.nct create mode 100644 tests/lvl2localrecord.nct create mode 100644 tests/lvl2symbolrecord.nct diff --git a/tests/Exporter.nct b/tests/Exporter.nct new file mode 100644 index 0000000..33e60a9 --- /dev/null +++ b/tests/Exporter.nct @@ -0,0 +1,5 @@ +u32 SYMBOL: 1234; + +record Foo { + u32 gaga; +} diff --git a/tests/GenericStruct.nct b/tests/GenericStruct.nct new file mode 100644 index 0000000..12cc30c --- /dev/null +++ b/tests/GenericStruct.nct @@ -0,0 +1,44 @@ +record StaticList[T, S; capacity] { + S size; + T[capacity] data; +} + +StaticList_remove: [T, S; capacity]u0(StaticList[T, S; capacity]* this, S index) -> { + T* data = &((*this).data[index]); + (*this).size = (*this).size - 1; + S sz = (*this).size; + loop { + if(index == sz) { + break; + } + + *data = *(data + 1); + + data = data + 1; + index = index + 1; + } + return; +}; + +StaticList_add: [T, S; capacity]u0(StaticList[T, S; capacity]* this, T value) -> { + (*this).data[(*this).size] = value; + (*this).size = (*this).size + 1; + return; +}; + +@instantiate StaticList_remove[u8, u32; 4]; +@instantiate StaticList_add[u8, u32; 4]; + +/*StaticList[u8, u32; 4] kbbuf; + +kbbuf.size = 4; +kbbuf.data[0] = 0; +kbbuf.data[5] = 2; + +foo: [T]T(T a, T b) -> { + return a + b; +}; + +@instantiate foo[u32]; + +u32 c = foo[u32](5, 3);*/ diff --git a/tests/Importer.nct b/tests/Importer.nct new file mode 100644 index 0000000..3e30b7c --- /dev/null +++ b/tests/Importer.nct @@ -0,0 +1,3 @@ +use Exporter; + +u32 a = Exporter.SYMBOL; diff --git a/tests/UDPEcho.nct b/tests/UDPEcho.nct new file mode 100644 index 0000000..46aa547 --- /dev/null +++ b/tests/UDPEcho.nct @@ -0,0 +1,43 @@ +@section(".text"); + +record sockaddr { +0: u16 family; +2: u16 port; +4: u32 addr; +8: u32 zero0; +12: u32 zero1; +} + +extern u32(u32, u32, u32) socket; +extern u32(u32, sockaddr*, u32) bind; +extern u32(u32, u8*, u32, u32, u8*, u32*) recvfrom; +extern u32(u32, u8*, u32, u32, u8*, u32) sendto; + +MY_SOCKET = socket(2, 2, 0); + +sockaddr sa; +sa.family = 2; /* AF_INET */ +sa.port = 43105; /* 25000 in net-endian */ +sa.addr = 0; /* Bind to all */ +sa.zero0 = 0; +sa.zero1 = 0; + +bind(MY_SOCKET, &sa, 16); + +loop { + + OTHER_SIDE_LEN = 64; + u32 msglength = recvfrom(MY_SOCKET, &BUFFER, 512, 0, &OTHER_SIDE, &OTHER_SIDE_LEN); + + sendto(MY_SOCKET, &BUFFER, msglength, 0, &OTHER_SIDE, OTHER_SIDE_LEN); + +} + +@section(".data"); + +u32 MY_SOCKET:; + +u32 OTHER_SIDE_LEN:; +u8[64] OTHER_SIDE:; + +u8[512] BUFFER:; diff --git a/tests/lvl1localrecord.nct b/tests/lvl1localrecord.nct new file mode 100644 index 0000000..61d3950 --- /dev/null +++ b/tests/lvl1localrecord.nct @@ -0,0 +1,16 @@ +record sockaddr { + u32 family; + u16 port; + u32 addr; + u32 zero; +} + +@section(".data"); + +@section(".text"); + +sockaddr sa; +sa.family = 5; +sa.port = 43105; +sa.addr = 16rC0A80001; +sa.zero = 0; diff --git a/tests/lvl1symbolrecord.nct b/tests/lvl1symbolrecord.nct new file mode 100644 index 0000000..82fd14b --- /dev/null +++ b/tests/lvl1symbolrecord.nct @@ -0,0 +1,17 @@ +record sockaddr { + u32 family; + u16 port; + u32 addr; + u32 zero; +} + +@section(".data"); + +sockaddr sa:; + +@section(".text"); + +sa.family = 5; +sa.port = 43105; +sa.addr = 16rC0A80001; +sa.zero = 0; diff --git a/tests/lvl2localrecord.nct b/tests/lvl2localrecord.nct new file mode 100644 index 0000000..ac78b5b --- /dev/null +++ b/tests/lvl2localrecord.nct @@ -0,0 +1,16 @@ +record A { + u32 x; + u8 z; +} + +record B { + 0: u32 x; + 7: A a; +} + +@section(".text"); + +B rec; +rec.x = 5; +rec.a.x = 10; +rec.a.z = 9; diff --git a/tests/lvl2symbolrecord.nct b/tests/lvl2symbolrecord.nct new file mode 100644 index 0000000..5c8632a --- /dev/null +++ b/tests/lvl2symbolrecord.nct @@ -0,0 +1,19 @@ +record A { + u32 x; + u8 z; +} + +record B { + u32 x; + A a; +} + +@section(".data"); + +B rec:; + +@section(".text"); + +rec.x = 5; +rec.a.x = 10; +rec.a.z = 9;