forked from starnakin/IronGOLEM
Compare commits
41 Commits
6051375f6a
...
master
Author | SHA1 | Date | |
---|---|---|---|
e417a01f9a | |||
21c78421a4 | |||
f05f3945fe | |||
ba9c1f8c11 | |||
7f6225d8dd | |||
0b09f0d262 | |||
69a044b3fa | |||
e9bf776069 | |||
ed23a887f9 | |||
4bd9f50bd4 | |||
58f9c0cf9e | |||
cc965024d6 | |||
2421c51116 | |||
78bc62c044 | |||
57de93e799 | |||
9a23536491 | |||
54370e872e | |||
106d2da5a0 | |||
c41ebf6ff5 | |||
a84415a953 | |||
470b97446b | |||
09e0d32c15 | |||
2b97d38b7e | |||
cb41e69bdb | |||
cc53b0cda5 | |||
a432fd32c5 | |||
15d00356e4 | |||
c4ce5b8566 | |||
1452a70b85 | |||
575ed7aa64 | |||
46d7e9c85c | |||
ee80b05d10 | |||
2fab31d822 | |||
a7e050c351 | |||
a39e4a780d | |||
0c782738cc | |||
1a1251b512 | |||
d3e788868a | |||
5dcace0cbe | |||
85aeaebc7a | |||
3443ed76e8 |
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,3 +1,3 @@
|
||||
tmp.rom
|
||||
tmp.asm
|
||||
tmp.🗿
|
||||
IronGolem.asm
|
||||
IronGolem.🗿
|
||||
tmp.*
|
||||
|
14
README.md
14
README.md
@ -17,8 +17,20 @@ You can simply add the [latest release](https://git.chauvet.pro/starnakin/IronGO
|
||||
- [aton](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/aton)
|
||||
- [aton_s](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/aton_s)
|
||||
- [bzero](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/bzero)
|
||||
- [aton_s](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/aton_s)
|
||||
- [galloc](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/galloc)
|
||||
- [free](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/free)
|
||||
- [leaks](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/leaks)
|
||||
- [ntoa](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/ntoa)
|
||||
- [ntoa_s](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/ntoa_s)
|
||||
- [geadline](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/geadline)
|
||||
- [geadline2](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/geadline2)
|
||||
- [strcat](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strcat)
|
||||
- [strcpy](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strcpy)
|
||||
- [strncpy](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strncpy)
|
||||
- [strlen](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strlen)
|
||||
- [strncmp](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strncmp)
|
||||
- [strcmp](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strcmp)
|
||||
- [strchr](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strchr)
|
||||
- [strstr](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strstr)
|
||||
- [strndup](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strndup)
|
||||
- [strdup](https://git.chauvet.pro/starnakin/IronGOLEM/wiki/strdup)
|
4
run.sh
4
run.sh
@ -1,4 +1,4 @@
|
||||
cat src/* >tmp.🗿
|
||||
golemc tmp.🗿 >tmp.asm
|
||||
cat src/* > IronGolem.🗿
|
||||
golemc IronGolem.🗿 > IronGolem.asm
|
||||
# orgaasm tmp.asm tmp.rom
|
||||
# orgaemu tmp.rom
|
||||
|
14
src/aton.🗿
14
src/aton.🗿
@ -1,18 +1,16 @@
|
||||
aton(str)
|
||||
{
|
||||
local i = 0;
|
||||
local out = 0;
|
||||
|
||||
loop {
|
||||
if ([str + i] != '+')
|
||||
if ([str] != '+')
|
||||
break;
|
||||
i++;
|
||||
str++;
|
||||
}
|
||||
loop {
|
||||
if ([str + i] == 0 | isdigit([str + i]) == 0)
|
||||
break;
|
||||
out = out * 10 + [str + i] - '0';
|
||||
i++;
|
||||
if ([str] == 0 | isdigit([str]) == 0)
|
||||
return out;
|
||||
out = out * 10 + [str] - '0';
|
||||
str++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
18
src/aton_s.🗿
18
src/aton_s.🗿
@ -1,23 +1,19 @@
|
||||
aton_s(str)
|
||||
{
|
||||
local i = 0;
|
||||
local sign = 0;
|
||||
local out = 0;
|
||||
|
||||
loop {
|
||||
if ([str + i] == '-')
|
||||
if ([str] == '-')
|
||||
sign = sign == 0;
|
||||
else if ([str + i] != '+')
|
||||
else if ([str] != '+')
|
||||
break;
|
||||
i++;
|
||||
str++;
|
||||
}
|
||||
loop {
|
||||
if ([str + i] == 0 | isdigit([str + i]) == 0)
|
||||
break;
|
||||
out = out * 10 + [str + i] - '0';
|
||||
i++;
|
||||
if ([str] == 0 | isdigit([str]) == 0)
|
||||
return (sign * (0 - out)) | ((sign == 0) * out);
|
||||
out = out * 10 + [str] - '0';
|
||||
str++;
|
||||
}
|
||||
if (sign)
|
||||
return (0 - out);
|
||||
return out;
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
bzero(tab, size) memset(tab, size, 0);
|
||||
bzero(tab, size) => memset(tab, size, 0);
|
||||
|
11
src/contain_only.🗿
Normal file
11
src/contain_only.🗿
Normal file
@ -0,0 +1,11 @@
|
||||
contain_only(to_big, to_find)
|
||||
{
|
||||
loop
|
||||
{
|
||||
if ([to_big] == 0)
|
||||
return 1;
|
||||
if (strchr(to_find, [to_big]) == 0)
|
||||
return 0;
|
||||
to_big++;
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
enum MAP_KEY, MAP_VALUE;
|
||||
define MAP_SIZE=2;
|
||||
|
||||
define NUM_MAX = 0xffff;
|
||||
define NUM_MIN = 0x0000;
|
||||
define NUM_S_MIN = 0x8000;
|
||||
|
@ -9,5 +9,5 @@ free_tab(tab)
|
||||
free([tmp]);
|
||||
tmp++;
|
||||
}
|
||||
free(tab);
|
||||
return free(tab);
|
||||
}
|
||||
|
51
src/galgrind.🗿
Normal file
51
src/galgrind.🗿
Normal file
@ -0,0 +1,51 @@
|
||||
invalid_write(ptr, i)
|
||||
{
|
||||
if (i < GALLOC_PADDING_SIZE & [ptr + GALLOC_HEADER_SIZE + i])
|
||||
return ptr + GALLOC_HEADER_SIZE + i;
|
||||
if (i >= GALLOC_PADDING_SIZE & [ptr + GALLOC_DATA + i - GALLOC_PADDING_SIZE + [ptr + GALLOC_SIZE]])
|
||||
return ptr + GALLOC_DATA + i - GALLOC_PADDING_SIZE + [ptr + GALLOC_SIZE];
|
||||
return 0;
|
||||
}
|
||||
|
||||
galgrind()
|
||||
{
|
||||
local ptr = heap;
|
||||
local i;
|
||||
|
||||
loop
|
||||
{
|
||||
if (ptr == NULL)
|
||||
return 0;
|
||||
if ([ptr + GALLOC_USED] == 1)
|
||||
{
|
||||
putstr("block: ");
|
||||
putnum(ptr - heap);
|
||||
putstr(", size: ");
|
||||
putnum([ptr + GALLOC_SIZE]);
|
||||
putstr("cases");
|
||||
putstr(", start: ");
|
||||
putnum(ptr - heap + GALLOC_DATA);
|
||||
putstr(", end: ");
|
||||
putnum(ptr - heap + GALLOC_DATA + [ptr + GALLOC_SIZE]);
|
||||
putstr(", start galloc block: ");
|
||||
putnum(ptr - heap);
|
||||
putstr(", end galloc block: ");
|
||||
putnum(ptr - heap + GALLOC_DATA + [ptr + GALLOC_SIZE] + GALLOC_PADDING_SIZE);
|
||||
putchar('\n');
|
||||
i = 0;
|
||||
loop
|
||||
{
|
||||
if (i == GALLOC_PADDING_SIZE * 2)
|
||||
break;
|
||||
if (invalid_write(ptr, i))
|
||||
{
|
||||
putnum(invalid_write(ptr, i) - heap);
|
||||
putchar('\n');
|
||||
}
|
||||
i++;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
ptr = [ptr + GALLOC_NEXT];
|
||||
}
|
||||
}
|
82
src/galloc.🗿
82
src/galloc.🗿
@ -1,8 +1,8 @@
|
||||
define HEAP_SIZE = 0x8000;
|
||||
define HEAP_SIZE = 0x4000;
|
||||
global heap[HEAP_SIZE] = 0;
|
||||
|
||||
define PADDING_SIZE = 4;
|
||||
define HEADER_SIZE = 5;
|
||||
define GALLOC_PADDING_SIZE = 4;
|
||||
define GALLOC_HEADER_SIZE = 5;
|
||||
|
||||
🗿HEADER REPRESENTATION
|
||||
🗿+-------------+--------+--------+-------------------------------+---------------------------+---------+---------+---------+
|
||||
@ -26,30 +26,26 @@ define HEADER_SIZE = 5;
|
||||
🗿 Is used to check invalid write
|
||||
🗿 If a case doesn't equal to 0 it is an invalid write
|
||||
|
||||
define LOCATION_INITIALISED = 0;
|
||||
define LOCATION_USED = 1;
|
||||
define LOCATION_SIZE = 2;
|
||||
define LOCATION_PREV = 3;
|
||||
define LOCATION_NEXT = 4;
|
||||
define LOCATION_DATA = HEADER_SIZE + PADDING_SIZE;
|
||||
enum GALLOC_INITIALISED, GALLOC_USED, GALLOC_SIZE, GALLOC_PREV, GALLOC_NEXT;
|
||||
define GALLOC_DATA = GALLOC_HEADER_SIZE + GALLOC_PADDING_SIZE;
|
||||
|
||||
galloc_setup_header(ptr, used, size, next_block, prev_block)
|
||||
{
|
||||
local i;
|
||||
|
||||
[ptr + LOCATION_INITIALISED] = 1;
|
||||
[ptr + LOCATION_USED] = used;
|
||||
[ptr + LOCATION_SIZE] = size;
|
||||
[ptr + LOCATION_PREV] = prev_block;
|
||||
[ptr + LOCATION_NEXT] = next_block;
|
||||
[ptr + GALLOC_INITIALISED] = 1;
|
||||
[ptr + GALLOC_USED] = used;
|
||||
[ptr + GALLOC_SIZE] = size;
|
||||
[ptr + GALLOC_PREV] = prev_block;
|
||||
[ptr + GALLOC_NEXT] = next_block;
|
||||
|
||||
i = HEADER_SIZE;
|
||||
i = GALLOC_HEADER_SIZE;
|
||||
loop
|
||||
{
|
||||
if (i == HEADER_SIZE + PADDING_SIZE)
|
||||
if (i == GALLOC_HEADER_SIZE + GALLOC_PADDING_SIZE)
|
||||
break;
|
||||
[ptr + i] = 0; 🗿 INITIALISE TOP PADDING
|
||||
[ptr + i + PADDING_SIZE + size] = 0; 🗿 INITIALISE BOT PADDING
|
||||
[ptr + i + GALLOC_HEADER_SIZE] = 0; 🗿 INITIALISE TOP PADDING
|
||||
[ptr + i + GALLOC_PADDING_SIZE + size] = 0; 🗿 INITIALISE BOT PADDING
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -61,10 +57,10 @@ galloc_find_next_space(size)
|
||||
current = heap;
|
||||
loop
|
||||
{
|
||||
if ([current + LOCATION_USED] == 0
|
||||
& [current + LOCATION_SIZE] >= size)
|
||||
if ([current + GALLOC_USED] == 0
|
||||
& [current + GALLOC_SIZE] >= size)
|
||||
return (current);
|
||||
current = [current + LOCATION_NEXT];
|
||||
current = [current + GALLOC_NEXT];
|
||||
if (current == 0)
|
||||
return (0);
|
||||
}
|
||||
@ -91,18 +87,18 @@ galloc_split_block(ptr, size)
|
||||
local prev;
|
||||
local old_size;
|
||||
|
||||
old_size = [ptr + LOCATION_SIZE];
|
||||
if (size + HEADER_SIZE + PADDING_SIZE * 2 > old_size) 🗿 if the block is to small to be split
|
||||
old_size = [ptr + GALLOC_SIZE];
|
||||
if (size + GALLOC_HEADER_SIZE + GALLOC_PADDING_SIZE * 2 > old_size) 🗿 if the block is to small to be split
|
||||
{
|
||||
[ptr + LOCATION_USED] = 1;
|
||||
[ptr + GALLOC_USED] = 1;
|
||||
return (ptr);
|
||||
}
|
||||
old_next = [ptr + LOCATION_NEXT];
|
||||
next = ptr + size + HEADER_SIZE + PADDING_SIZE * 2;
|
||||
prev = [ptr + LOCATION_PREV];
|
||||
old_next = [ptr + GALLOC_NEXT];
|
||||
next = ptr + size + GALLOC_HEADER_SIZE + GALLOC_PADDING_SIZE * 2;
|
||||
prev = [ptr + GALLOC_PREV];
|
||||
🗿 galloc_setup_header(ptr, used, size, next_block, prev_block);
|
||||
galloc_setup_header(ptr, 1, size, ptr + HEADER_SIZE + PADDING_SIZE * 2 + size, prev);
|
||||
galloc_setup_header(next, 0, old_size - size - HEADER_SIZE - PADDING_SIZE * 2, old_next, ptr);
|
||||
galloc_setup_header(ptr, 1, size, ptr + GALLOC_HEADER_SIZE + GALLOC_PADDING_SIZE * 2 + size, prev);
|
||||
galloc_setup_header(next, 0, old_size - size - GALLOC_HEADER_SIZE - GALLOC_PADDING_SIZE * 2, old_next, ptr);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -111,17 +107,17 @@ galloc(size)
|
||||
local ptr;
|
||||
|
||||
if ([heap] == 0) 🗿 if the heap is not initialised
|
||||
galloc_setup_header(heap, 0, HEAP_SIZE - HEADER_SIZE - PADDING_SIZE * 2, 0, 0); 🗿 initialised all the heap
|
||||
galloc_setup_header(heap, 0, HEAP_SIZE - GALLOC_HEADER_SIZE - GALLOC_PADDING_SIZE * 2, 0, 0); 🗿 initialised all the heap
|
||||
ptr = galloc_find_next_space(size);
|
||||
if (ptr == 0)
|
||||
return (0);
|
||||
if ([ptr + LOCATION_SIZE] == size)
|
||||
if ([ptr + GALLOC_SIZE] == size)
|
||||
{
|
||||
[ptr + LOCATION_USED] = 1;
|
||||
return (ptr + LOCATION_DATA);
|
||||
[ptr + GALLOC_USED] = 1;
|
||||
return (ptr + GALLOC_DATA);
|
||||
}
|
||||
galloc_split_block(ptr, size);
|
||||
return (ptr + LOCATION_DATA);
|
||||
return (ptr + GALLOC_DATA);
|
||||
}
|
||||
|
||||
galloc_merge_blocks(first_block, last_block)
|
||||
@ -130,10 +126,10 @@ galloc_merge_blocks(first_block, last_block)
|
||||
|
||||
if (last_block == first_block)
|
||||
{
|
||||
galloc_setup_header(first_block, 0, [first_block + LOCATION_SIZE], [first_block + LOCATION_NEXT], [first_block + LOCATION_PREV]);
|
||||
galloc_setup_header(first_block, 0, [first_block + GALLOC_SIZE], [first_block + GALLOC_NEXT], [first_block + GALLOC_PREV]);
|
||||
}
|
||||
size = last_block - first_block + [last_block + LOCATION_SIZE];
|
||||
galloc_setup_header(first_block, 0, size, [last_block + LOCATION_NEXT], [first_block + LOCATION_PREV]);
|
||||
size = last_block - first_block + [last_block + GALLOC_SIZE];
|
||||
galloc_setup_header(first_block, 0, size, [last_block + GALLOC_NEXT], [first_block + GALLOC_PREV]);
|
||||
}
|
||||
|
||||
free(ptr)
|
||||
@ -149,14 +145,14 @@ free(ptr)
|
||||
putstr("Error: free: invalid ptr\n");
|
||||
return;
|
||||
}
|
||||
block = ptr - LOCATION_DATA;
|
||||
prev_block = [block + LOCATION_PREV];
|
||||
if (prev_block == 0 | [prev_block + LOCATION_USED])
|
||||
block = ptr - GALLOC_DATA;
|
||||
prev_block = [block + GALLOC_PREV];
|
||||
if (prev_block == 0 | [prev_block + GALLOC_USED])
|
||||
first_block = block;
|
||||
else
|
||||
first_block = prev_block;
|
||||
next_block = [block + LOCATION_NEXT];
|
||||
if (next_block == 0 | [next_block + LOCATION_USED])
|
||||
next_block = [block + GALLOC_NEXT];
|
||||
if (next_block == 0 | [next_block + GALLOC_USED])
|
||||
last_block = block;
|
||||
else
|
||||
last_block = next_block;
|
||||
@ -165,5 +161,5 @@ free(ptr)
|
||||
|
||||
leaks()
|
||||
{
|
||||
return ([heap + LOCATION_NEXT] != 0);
|
||||
return ([heap + GALLOC_NEXT] != 0);
|
||||
}
|
||||
|
121
src/geadline.🗿
121
src/geadline.🗿
@ -1,49 +1,132 @@
|
||||
geadline(prompt) {
|
||||
geadline2(prompt, text)
|
||||
{
|
||||
local capacity = 64,
|
||||
size = 0,
|
||||
i = 0,
|
||||
c,
|
||||
buf = galloc(capacity);
|
||||
a,
|
||||
buf;
|
||||
if (text) {
|
||||
size = strlen(text);
|
||||
i = size;
|
||||
loop {
|
||||
if (capacity > size)
|
||||
break;
|
||||
capacity = capacity * 2;
|
||||
}
|
||||
buf = galloc(capacity);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
strcpy(buf, text);
|
||||
} else {
|
||||
buf = galloc(capacity);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
[buf] = 0;
|
||||
}
|
||||
if (prompt)
|
||||
putstr(prompt);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
putstr(buf);
|
||||
|
||||
loop {
|
||||
red &c;
|
||||
c = getchar();
|
||||
if ((c == 0xffff) | (c == 0x04)) {
|
||||
if ((size == 0) | (c == 0xffff)) {
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
} else if (c == 0x007f) {
|
||||
if (size) {
|
||||
} else if (c == 0x1b) {
|
||||
// ESC code
|
||||
getchar(); // skip [
|
||||
c = getchar(); // value
|
||||
|
||||
if ((c == 'A') & (size > 0)) {
|
||||
loop {
|
||||
if (i == 0)
|
||||
break;
|
||||
i = i - 1;
|
||||
esccode('D');
|
||||
}
|
||||
} else if ((c == 'B') & (i < size)) {
|
||||
loop {
|
||||
if (i >= size)
|
||||
break;
|
||||
i = i + 1;
|
||||
esccode('C');
|
||||
}
|
||||
} else if ((c == 'C') & (i < size)) {
|
||||
i = i + 1;
|
||||
esccode('C');
|
||||
} else if ((c == 'D') & (i > 0)) {
|
||||
i = i - 1;
|
||||
esccode('D');
|
||||
}
|
||||
wrt '\a';
|
||||
} else if (c == 0x7f) {
|
||||
if (i) {
|
||||
a = i - 1;
|
||||
loop {
|
||||
if (a >= size)
|
||||
break;
|
||||
[buf + a] = [buf + a + 1];
|
||||
a = a + 1;
|
||||
}
|
||||
size = size - 1;
|
||||
i = i - 1;
|
||||
[buf + size] = 0;
|
||||
|
||||
wrt 0x1b;
|
||||
wrt 0x5b;
|
||||
wrt 0x44;
|
||||
wrt '\r';
|
||||
if (prompt)
|
||||
putstr(prompt);
|
||||
putstr(buf);
|
||||
wrt ' ';
|
||||
wrt 0x1b;
|
||||
wrt 0x5b;
|
||||
wrt 0x44;
|
||||
esccode('D');
|
||||
a = size - i;
|
||||
loop {
|
||||
if (a == 0)
|
||||
break;
|
||||
a = a - 1;
|
||||
esccode('D');
|
||||
}
|
||||
}
|
||||
} else if (c == '\n') {
|
||||
wrt '\n';
|
||||
return buf;
|
||||
} else {
|
||||
size = size + 1;
|
||||
if (size > capacity) {
|
||||
buf = reallocarray(buf, capacity, capacity * 2);
|
||||
if (size >= capacity) {
|
||||
buf = realloc(buf, capacity * 2);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
capacity = capacity * 2;
|
||||
}
|
||||
a = size - i - 1;
|
||||
loop {
|
||||
if ((a == 0xffff) | (a == 0))
|
||||
break;
|
||||
[buf + i + a] = [buf + i + a - 1];
|
||||
a = a - 1;
|
||||
}
|
||||
[buf + i] = c;
|
||||
[buf + size] = 0;
|
||||
putstr(buf + i);
|
||||
a = strlen(buf + i) - 1;
|
||||
loop {
|
||||
if ((a == 0xffff) | (a == 0))
|
||||
break;
|
||||
a = a - 1;
|
||||
esccode('D');
|
||||
}
|
||||
i = i + 1;
|
||||
[buf + i] = 0;
|
||||
wrt c;
|
||||
if (c == '\n')
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
geadline(prompt) => geadline2(prompt, NULL);
|
||||
|
||||
esccode(c)
|
||||
{
|
||||
wrt 0x1b;
|
||||
wrt '[';
|
||||
wrt c;
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
define GET_LINE_BUFFER=100;
|
||||
|
||||
get_line()
|
||||
{
|
||||
local tmp;
|
||||
local out;
|
||||
local c;
|
||||
local i;
|
||||
|
||||
out = NULL;
|
||||
i = 0;
|
||||
loop
|
||||
{
|
||||
if (i % GET_LINE_BUFFER == 0)
|
||||
{
|
||||
tmp = reallocarray(out, i, i + GET_LINE_BUFFER + 1);
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
}
|
||||
red &c;
|
||||
if (c == 0xffff)
|
||||
return NULL;
|
||||
[tmp + i] = c;
|
||||
i++;
|
||||
if (c == '\n')
|
||||
break;
|
||||
}
|
||||
[tmp + i] = 0;
|
||||
out = strdup(tmp);
|
||||
free(tmp);
|
||||
return out;
|
||||
}
|
6
src/getchar.🗿
Normal file
6
src/getchar.🗿
Normal file
@ -0,0 +1,6 @@
|
||||
getchar()
|
||||
{
|
||||
local c;
|
||||
red &c;
|
||||
return c;
|
||||
}
|
@ -1 +1 @@
|
||||
isalpha(c) return (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z');
|
||||
isalpha(c) => (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z');
|
||||
|
@ -1 +1 @@
|
||||
isascii(c) return c < 128;
|
||||
isascii(c) => c < 128;
|
||||
|
@ -1 +1 @@
|
||||
isdigit(c) return c >= '0' & c <= '9';
|
||||
isdigit(c) => c >= '0' & c <= '9';
|
||||
|
@ -1 +1 @@
|
||||
isalnum(c) return isalpha(c) | isdigit(c);
|
||||
isalnum(c) => isalpha(c) | isdigit(c);
|
||||
|
@ -1 +1 @@
|
||||
isprint(c) return c >= ' ' & c <= '~';
|
||||
isprint(c) => c >= ' ' & c <= '~';
|
||||
|
@ -5,6 +5,7 @@ memset(tab, size, value)
|
||||
loop {
|
||||
if (i == size)
|
||||
return (tab);
|
||||
[tab + i++] = value;
|
||||
[tab + i] = value;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ ntoa_get_size(number)
|
||||
local size = 0;
|
||||
|
||||
if (number == 0)
|
||||
size++;
|
||||
return 1;
|
||||
loop
|
||||
{
|
||||
if (number == 0)
|
||||
@ -29,8 +29,8 @@ ntoa(number)
|
||||
{
|
||||
if (number == 0)
|
||||
return (str);
|
||||
[str + size - 1] = number % 10 + '0';
|
||||
number = number / 10;
|
||||
size--;
|
||||
[str + size] = number % 10 + '0';
|
||||
number = number / 10;
|
||||
}
|
||||
}
|
||||
|
15
src/ntoa_s.🗿
15
src/ntoa_s.🗿
@ -1,18 +1,3 @@
|
||||
ntoa_get_size(number)
|
||||
{
|
||||
local size = 0;
|
||||
|
||||
if (number == 0)
|
||||
size++;
|
||||
loop
|
||||
{
|
||||
if (number == 0)
|
||||
return (size);
|
||||
number = number / 10;
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
ntoa_s(number)
|
||||
{
|
||||
local str, sign, size;
|
||||
|
@ -1,6 +1,6 @@
|
||||
print_raw_bit(number)
|
||||
{
|
||||
local tab = get_raw_bit(number), i = 0;
|
||||
local tab = get_raw_bit(number);
|
||||
puttab_num(tab, 16);
|
||||
free(tab);
|
||||
}
|
||||
|
@ -1 +1,5 @@
|
||||
putchar(c) wrt c;
|
||||
putchar(c)
|
||||
{
|
||||
wrt c;
|
||||
return c;
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
putnum(number)
|
||||
{
|
||||
local str;
|
||||
str = ntoa(number);
|
||||
if (str == 0)
|
||||
return;
|
||||
local str = ntoa(number);
|
||||
putstr(str);
|
||||
free(str);
|
||||
}
|
||||
|
14
src/putstr.🗿
14
src/putstr.🗿
@ -1,10 +1,14 @@
|
||||
putstr(str)
|
||||
{
|
||||
local i = 0;
|
||||
local tmp = str;
|
||||
if (str == NULL) {
|
||||
putstr("(null)");
|
||||
return NULL;
|
||||
}
|
||||
loop {
|
||||
if ([str + i] == 0)
|
||||
return;
|
||||
putchar([str + i]);
|
||||
i++;
|
||||
if ([tmp] == 0)
|
||||
return str;
|
||||
putchar([tmp]);
|
||||
tmp++;
|
||||
}
|
||||
}
|
||||
|
22
src/puttab.🗿
22
src/puttab.🗿
@ -1,20 +1,19 @@
|
||||
puttab_str(tab)
|
||||
{
|
||||
local tmp = tab;
|
||||
|
||||
putchar('[');
|
||||
loop
|
||||
{
|
||||
if ([tmp] == 0)
|
||||
break;
|
||||
if ([tab] == 0) {
|
||||
putchar(']');
|
||||
return;
|
||||
}
|
||||
putchar('"');
|
||||
putstr([tmp]);
|
||||
putstr([tab]);
|
||||
putchar('"');
|
||||
if ([tmp + 1] != 0)
|
||||
tab++;
|
||||
if ([tab] != 0)
|
||||
putstr(", ");
|
||||
tmp++;
|
||||
}
|
||||
putchar(']');
|
||||
}
|
||||
|
||||
puttab_num(tab, size)
|
||||
@ -24,12 +23,13 @@ puttab_num(tab, size)
|
||||
putchar('[');
|
||||
loop
|
||||
{
|
||||
if (i == size)
|
||||
break;
|
||||
if (i == size) {
|
||||
putchar(']');
|
||||
return;
|
||||
}
|
||||
putnum([tab + i]);
|
||||
i++;
|
||||
if (i != size)
|
||||
putstr(", ");
|
||||
}
|
||||
putchar(']');
|
||||
}
|
||||
|
@ -1,21 +1,26 @@
|
||||
reallocarray(ptr, nmemb, size)
|
||||
realloc(ptr, new_size)
|
||||
{
|
||||
local tmp;
|
||||
local start;
|
||||
local block_ptr;
|
||||
local new_space;
|
||||
local i;
|
||||
|
||||
start = ptr;
|
||||
tmp = galloc(size);
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
new_space = galloc(new_size);
|
||||
if (new_space == NULL)
|
||||
{
|
||||
free(ptr);
|
||||
return (NULL);
|
||||
}
|
||||
if (ptr == NULL)
|
||||
return tmp;
|
||||
return new_space;
|
||||
block_ptr = ptr - GALLOC_DATA;
|
||||
i = 0;
|
||||
loop
|
||||
{
|
||||
if (start - ptr == nmemb)
|
||||
if (i == new_size | i == [block_ptr + GALLOC_SIZE])
|
||||
break;
|
||||
[tmp + start - ptr] = [start];
|
||||
start++;
|
||||
[new_space + i] = [ptr + i];
|
||||
i++;
|
||||
}
|
||||
free(ptr);
|
||||
return tmp;
|
||||
return new_space;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
replace(str, fill, start, stop)
|
||||
replace_index(str, fill, start, stop)
|
||||
{
|
||||
local out;
|
||||
local sum;
|
10
src/strchr.🗿
10
src/strchr.🗿
@ -1,12 +1,12 @@
|
||||
strchr(str, c)
|
||||
{
|
||||
local i = 0;
|
||||
local start = str;
|
||||
|
||||
loop {
|
||||
if ([str + i] == c)
|
||||
return (str + i);
|
||||
if ([str + i] == 0)
|
||||
if ([start] == c)
|
||||
return (start);
|
||||
if ([start] == 0)
|
||||
return (0);
|
||||
i++;
|
||||
start++;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
strchri(str, c)
|
||||
{
|
||||
local i = 0;
|
||||
|
||||
loop {
|
||||
if ([str + i] == c)
|
||||
return (i);
|
||||
if ([str + i] == 0)
|
||||
return (0 - 1);
|
||||
i++;
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
strlen(str) {
|
||||
local i = 0;
|
||||
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
loop {
|
||||
if ([str + i] == 0)
|
||||
return (i);
|
||||
|
9
test.sh
9
test.sh
@ -6,13 +6,18 @@ tester()
|
||||
cat src/*.🗿 tests/$val.🗿 tests/test.🗿 >tmp.🗿
|
||||
golemc tmp.🗿 > tmp.asm
|
||||
orgaasm tmp.asm tmp.rom
|
||||
orgaemu tmp.rom
|
||||
if [ -f tests/$val.input ]
|
||||
then
|
||||
orgaemu tmp.rom < tests/$val.input
|
||||
else
|
||||
orgaemu tmp.rom
|
||||
fi
|
||||
echo
|
||||
done
|
||||
}
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
tester $(ls tests/ | grep -v 'test.🗿' | sed 's/^tests\///; s/\.🗿$//' | tr '\n' ' ' );
|
||||
tester $(ls tests/*.🗿 | grep -v 'test.🗿' | sed 's/^tests\///; s/\.🗿$//' | tr '\n' ' ' );
|
||||
else
|
||||
tester $@;
|
||||
fi
|
||||
|
7
tests/contain_only.🗿
Normal file
7
tests/contain_only.🗿
Normal file
@ -0,0 +1,7 @@
|
||||
main()
|
||||
{
|
||||
name = "contain_only";
|
||||
|
||||
test_num(contain_only("17", "0123456789"), 1, "");
|
||||
test_num(contain_only("17a", "0123456789"), 0, "");
|
||||
}
|
@ -7,11 +7,11 @@ main()
|
||||
name = "galloc";
|
||||
|
||||
ptr1 = galloc(1);
|
||||
test_num(ptr1, heap + LOCATION_DATA, "");
|
||||
test_num(ptr1, heap + GALLOC_DATA, "");
|
||||
free(ptr1);
|
||||
|
||||
ptr1 = galloc(1);
|
||||
test_num(ptr1, heap + LOCATION_DATA, "alloc after free");
|
||||
test_num(ptr1, heap + GALLOC_DATA, "alloc after free");
|
||||
free(ptr1);
|
||||
|
||||
ptr2 = galloc(0x9000);
|
||||
|
3
tests/geadline.input
Normal file
3
tests/geadline.input
Normal file
@ -0,0 +1,3 @@
|
||||
yo
|
||||
bozo
|
||||
z[Dbo[C[C[Co
|
18
tests/geadline.🗿
Normal file
18
tests/geadline.🗿
Normal file
@ -0,0 +1,18 @@
|
||||
main()
|
||||
{
|
||||
local ptr;
|
||||
|
||||
name = "geadline";
|
||||
|
||||
ptr = geadline("");
|
||||
test_str(ptr, "yo", "");
|
||||
|
||||
ptr = geadline("");
|
||||
test_str(ptr, "bozo", "");
|
||||
|
||||
ptr = geadline("");
|
||||
test_str(ptr, "bozo", "arrow");
|
||||
|
||||
ptr = geadline("");
|
||||
test_num(ptr, 0, "");
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
define GET_LINE=0;
|
||||
main()
|
||||
{
|
||||
local ptr;
|
||||
|
||||
name = "get_line";
|
||||
if (GET_LINE == 0)
|
||||
return;
|
||||
|
||||
putstr("yo\n");
|
||||
ptr = get_line();
|
||||
test_str(ptr, "yo\n", "");
|
||||
free(ptr);
|
||||
|
||||
putstr("ENTER\n");
|
||||
ptr = get_line();
|
||||
test_str(ptr, "\n", "");
|
||||
free(ptr);
|
||||
|
||||
putstr("ctrl + D\n");
|
||||
ptr = get_line();
|
||||
test_num(ptr, NULL, "");
|
||||
}
|
@ -23,4 +23,12 @@ main()
|
||||
ptr = ntoa_s(0 - 1);
|
||||
test_str(ptr, "-1", "");
|
||||
free(ptr);
|
||||
|
||||
ptr = ntoa_s(0 - 3);
|
||||
test_str(ptr, "-3", "");
|
||||
free(ptr);
|
||||
|
||||
ptr = ntoa_s(3);
|
||||
test_str(ptr, "3", "");
|
||||
free(ptr);
|
||||
}
|
||||
|
24
tests/realloc.🗿
Normal file
24
tests/realloc.🗿
Normal file
@ -0,0 +1,24 @@
|
||||
main()
|
||||
{
|
||||
local ptr1;
|
||||
local ptr2;
|
||||
|
||||
name = "realloc";
|
||||
|
||||
ptr1 = strdup("yo");
|
||||
ptr2 = realloc(ptr1, 6);
|
||||
test_str("yo", ptr2, "standart: value");
|
||||
free(ptr2);
|
||||
test_num(leaks(), 0, "standart: leaks");
|
||||
|
||||
ptr2 = realloc(NULL, 6);
|
||||
test_num(heap + GALLOC_DATA, ptr2, "NULL: value");
|
||||
free(ptr2);
|
||||
test_num(leaks(), 0, "NULL: leaks");
|
||||
|
||||
ptr1 = strdup("bonjour");
|
||||
ptr2 = realloc(ptr1, 2);
|
||||
test_tab_num(ptr2, "bo", 2, "decrement size: value");
|
||||
free(ptr2);
|
||||
test_num(leaks(), 0, "decrement size: leaks");
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
main()
|
||||
{
|
||||
local tmp;
|
||||
name = "reallocarray";
|
||||
|
||||
tmp = strdup("yo");
|
||||
if (tmp == NULL)
|
||||
return 1;
|
||||
tmp = reallocarray(tmp, strlen(tmp), 5);
|
||||
test_str(tmp, "yo", "");
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
main()
|
||||
{
|
||||
name = "replace";
|
||||
|
||||
test_str(replace("yo ca va ?", "t", 2, 3), "yotca va ?", "");
|
||||
test_str(replace("yo ca va ?", "", 2, 3), "yoca va ?", "empty fill");
|
||||
test_str(replace("yo ca va ?", "aaaaa", 2, 3), "yoaaaaaca va ?", "");
|
||||
test_str(replace("", "aaaaa", 0, 0), "aaaaa", "");
|
||||
}
|
9
tests/replace_index.🗿
Normal file
9
tests/replace_index.🗿
Normal file
@ -0,0 +1,9 @@
|
||||
main()
|
||||
{
|
||||
name = "replace_index";
|
||||
|
||||
test_str(replace_index("yo ca va ?", "t", 2, 3), "yotca va ?", "");
|
||||
test_str(replace_index("yo ca va ?", "", 2, 3), "yoca va ?", "empty fill");
|
||||
test_str(replace_index("yo ca va ?", "aaaaa", 2, 3), "yoaaaaaca va ?", "");
|
||||
test_str(replace_index("", "aaaaa", 0, 0), "aaaaa", "");
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
main()
|
||||
{
|
||||
name = "strchri";
|
||||
|
||||
test_num(strchri("bozoman", 'm'), 4, "");
|
||||
test_num(strchri("bozoman", 'v'), 0 - 1, "");
|
||||
test_num(strchri("", 'v'), 0 - 1, "");
|
||||
}
|
14
wiki/strcat.md
Normal file
14
wiki/strcat.md
Normal file
@ -0,0 +1,14 @@
|
||||
# STRCAT
|
||||
Strcat (string concatenate) is a function that takes two chars lists as a parameter and write the second at this end of the first (like strcat in C)
|
||||
|
||||
## params
|
||||
1. chars list
|
||||
2. chars list
|
||||
|
||||
## example
|
||||
```
|
||||
strcat("y", "o") "y" => "yo"
|
||||
strcat("y", "") "y" => "y"
|
||||
strcat("", "o") "" => "o"
|
||||
strcat("hello ", "world!") => "hello world!"
|
||||
```
|
14
wiki/strcpy.md
Normal file
14
wiki/strcpy.md
Normal file
@ -0,0 +1,14 @@
|
||||
# STRCPY
|
||||
Strcpy (string copy) is a function that takes two chars lists as a parameter and write the second in the first (like strcpy in C)
|
||||
|
||||
## params
|
||||
1. chars list
|
||||
2. chars list
|
||||
|
||||
## example
|
||||
```
|
||||
strcpy("y", "o") "y" => "o"
|
||||
strcpy("y", "") "y" => ""
|
||||
strcpy("", "o") "" => "o"
|
||||
strcpy("hello ", "world!") => "world!"
|
||||
```
|
16
wiki/strlen.md
Normal file
16
wiki/strlen.md
Normal file
@ -0,0 +1,16 @@
|
||||
# STRLEN
|
||||
Strlen (string length) is a function that takes an chars list as a parameter and return an length (like strlen in C)
|
||||
|
||||
## params
|
||||
1. char list
|
||||
|
||||
## return
|
||||
number
|
||||
|
||||
## example
|
||||
```
|
||||
strlen("ab") => 2
|
||||
strlen(NULL) => 0
|
||||
strlen("") => 0
|
||||
strlen("j'ai les cramptés") => 17
|
||||
```
|
17
wiki/strncpy.md
Normal file
17
wiki/strncpy.md
Normal file
@ -0,0 +1,17 @@
|
||||
# STRNCPY
|
||||
Strncpy is a function that takes two chars lists and a number as a parameter and write the second in the first but only the n - 1 first char (like strncpy in C)
|
||||
|
||||
## params
|
||||
1. chars list
|
||||
2. chars list
|
||||
3. number
|
||||
|
||||
## example
|
||||
```
|
||||
strncpy("y", "o", 2) "y" => "o"
|
||||
strncpy("y", "", 1) "y" => ""
|
||||
strncpy("", "o", 2) "" => "o"
|
||||
strncpy("hello ", "world!", 7) => "world!"
|
||||
strncpy("hello ", "world!", 14) => "world!"
|
||||
strncpy("hello ", "world!", 0) => "hello "
|
||||
```
|
Reference in New Issue
Block a user