Initial commit

This commit is contained in:
Mid
2023-08-27 19:48:06 +03:00
commit 945bb2a672
33 changed files with 2751 additions and 0 deletions

2
tests/arrays.nct Normal file
View File

@@ -0,0 +1,2 @@
u32[5] arr;
arr[0] = 0;

81
tests/bf.nct Normal file
View File

@@ -0,0 +1,81 @@
@section(".data");
local u8[16384] data:;
local u8[16384] code:;
local u32[64] stck:;
@section(".text");
extern u32(u32, u8*, u32) write;
extern u32(u32, u8*, u32) read;
read(0, &code, 16384);
u32 codePtr = 0;
u32 dataPtr = 0;
u32 stckPtr = 16rFFFFFFFF;
loop {
if(code[codePtr] == 62) {
dataPtr = dataPtr + 1;
}
if(code[codePtr] == 60) {
dataPtr = dataPtr - 1;
}
if(code[codePtr] == 43) {
data[dataPtr] = data[dataPtr] + 1;
}
if(code[codePtr] == 45) {
data[dataPtr] = data[dataPtr] - 1;
}
if(code[codePtr] == 46) {
u32 z = &data + dataPtr;
write(1, z, 1);
}
if(code[codePtr] == 44) {
u32 z = &data + dataPtr;
read(0, z, 1);
}
if(code[codePtr] == 91) {
if(data[dataPtr] == 0) {
u32 depth = 0;
loop {
if(code[codePtr] == 91) {
depth = depth + 1;
}
if(code[codePtr] == 93) {
depth = depth - 1;
}
if(depth == 0) {
break;
}
codePtr = codePtr + 1;
}
}
if(data[dataPtr] != 0) {
stckPtr = stckPtr + 1;
stck[stckPtr] = codePtr;
}
codePtr = codePtr + 1;
continue;
}
if(code[codePtr] == 93) {
if(data[dataPtr] == 0) {
stckPtr = stckPtr - 1;
}
if(data[dataPtr] != 0) {
codePtr = stck[stckPtr];
}
}
if(code[codePtr] == 0) {
loop {}
}
codePtr = codePtr + 1;
}
codePtr;
dataPtr;
stckPtr;

2
tests/bit-rounding.nct Normal file
View File

@@ -0,0 +1,2 @@
u32 x: 123;
u33 y: 5;

10
tests/cat.nct Normal file
View File

@@ -0,0 +1,10 @@
extern u8(u8) putchar;
extern u32() getchar;
loop {
u32 a = getchar();
if(a == -1) {
break;
}
putchar(a);
}

9
tests/functions.nct Normal file
View File

@@ -0,0 +1,9 @@
extern u32() getchar;
extern void(u32) putchar;
loop {
u8 a = getchar();
if(a - 48) {
putchar(a);
}
}

11
tests/if.nct Normal file
View File

@@ -0,0 +1,11 @@
u16 x: 5;
loop {
u16* y = 257;
u9 w = -4;
u4 z = 3 + *y;
u2 o = -w;
if(x != 0) {
break;
}
}

22
tests/mbr.nct Normal file
View File

@@ -0,0 +1,22 @@
@org(16r7C00);
u8* dest = 16rB8000;
u8* src = &string;
loop {
if(*src == 0) {
break;
}
*dest = *src;
dest = dest + 1;
*dest = "_";
dest = dest + 1;
src = src + 1;
}
loop {}
u8[19] string: "Hello from Nectar!\0";
@align(510);
u16 bootsig: 16rAA55;

8
tests/ops.nct Normal file
View File

@@ -0,0 +1,8 @@
u16 a = 12;
u16 b = a & 6;
u16 c = b ^ a | 3;
u16 d = 11 * c;
if(a) {
u16 e = b + c + d;
}

5
tests/scoping.nct Normal file
View File

@@ -0,0 +1,5 @@
u8 a = 5;
if(a) {
u8 a = 10; /* Should not cause scoping errors. */
}
u8 b = 15; /* `a` in the if statement scope should be free'd. */