More tests

This commit is contained in:
Mid 2025-05-03 10:03:51 +03:00
parent 0d808de34c
commit 13f43cadeb
8 changed files with 163 additions and 0 deletions

5
tests/Exporter.nct Normal file
View File

@ -0,0 +1,5 @@
u32 SYMBOL: 1234;
record Foo {
u32 gaga;
}

44
tests/GenericStruct.nct Normal file
View File

@ -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);*/

3
tests/Importer.nct Normal file
View File

@ -0,0 +1,3 @@
use Exporter;
u32 a = Exporter.SYMBOL;

43
tests/UDPEcho.nct Normal file
View File

@ -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:;

16
tests/lvl1localrecord.nct Normal file
View File

@ -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;

View File

@ -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;

16
tests/lvl2localrecord.nct Normal file
View File

@ -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;

View File

@ -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;