forked from starnakin/IronGOLEM
Compare commits
16 Commits
cc53b0cda5
...
master
Author | SHA1 | Date | |
---|---|---|---|
e9bf776069 | |||
4bd9f50bd4 | |||
cc965024d6 | |||
2421c51116 | |||
78bc62c044 | |||
57de93e799 | |||
9a23536491 | |||
54370e872e | |||
106d2da5a0 | |||
c41ebf6ff5 | |||
a84415a953 | |||
470b97446b | |||
09e0d32c15 | |||
2b97d38b7e | |||
cb41e69bdb | |||
15d00356e4 |
@ -7,7 +7,7 @@ free_tab(tab)
|
|||||||
if ([tmp] == 0)
|
if ([tmp] == 0)
|
||||||
return;
|
return;
|
||||||
free([tmp]);
|
free([tmp]);
|
||||||
tmp = tmp + 1;
|
tmp++;
|
||||||
}
|
}
|
||||||
return free(tab);
|
return free(tab);
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,7 @@ define HEADER_SIZE = 5;
|
|||||||
🗿 Is used to check invalid write
|
🗿 Is used to check invalid write
|
||||||
🗿 If a case doesn't equal to 0 it is an invalid write
|
🗿 If a case doesn't equal to 0 it is an invalid write
|
||||||
|
|
||||||
define LOCATION_INITIALISED = 0;
|
enum LOCATION_INITIALISED, LOCATION_USED, LOCATION_SIZE, LOCATION_PREV, LOCATION_NEXT;
|
||||||
define LOCATION_USED = 1;
|
|
||||||
define LOCATION_SIZE = 2;
|
|
||||||
define LOCATION_PREV = 3;
|
|
||||||
define LOCATION_NEXT = 4;
|
|
||||||
define LOCATION_DATA = HEADER_SIZE + PADDING_SIZE;
|
define LOCATION_DATA = HEADER_SIZE + PADDING_SIZE;
|
||||||
|
|
||||||
galloc_setup_header(ptr, used, size, next_block, prev_block)
|
galloc_setup_header(ptr, used, size, next_block, prev_block)
|
||||||
|
@ -89,6 +89,9 @@ geadline2(prompt, text)
|
|||||||
esccode('D');
|
esccode('D');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (c == '\n') {
|
||||||
|
wrt '\n';
|
||||||
|
return buf;
|
||||||
} else {
|
} else {
|
||||||
size = size + 1;
|
size = size + 1;
|
||||||
if (size >= capacity) {
|
if (size >= capacity) {
|
||||||
@ -115,16 +118,11 @@ geadline2(prompt, text)
|
|||||||
esccode('D');
|
esccode('D');
|
||||||
}
|
}
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
if (c == '\n')
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
geadline(prompt)
|
geadline(prompt) => geadline2(prompt, NULL);
|
||||||
{
|
|
||||||
geadline2(prompt, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
esccode(c)
|
esccode(c)
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,6 @@ memset(tab, size, value)
|
|||||||
if (i == size)
|
if (i == size)
|
||||||
return (tab);
|
return (tab);
|
||||||
[tab + i] = value;
|
[tab + i] = value;
|
||||||
i = i + 1;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ ntoa_get_size(number)
|
|||||||
if (number == 0)
|
if (number == 0)
|
||||||
return (size);
|
return (size);
|
||||||
number = number / 10;
|
number = number / 10;
|
||||||
size = size + 1;
|
size++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ ntoa(number)
|
|||||||
{
|
{
|
||||||
if (number == 0)
|
if (number == 0)
|
||||||
return (str);
|
return (str);
|
||||||
size = size - 1;
|
size--;
|
||||||
[str + size] = number % 10 + '0';
|
[str + size] = number % 10 + '0';
|
||||||
number = number / 10;
|
number = number / 10;
|
||||||
}
|
}
|
||||||
|
19
src/ntoa_s.🗿
19
src/ntoa_s.🗿
@ -1,18 +1,3 @@
|
|||||||
ntoa_get_size(number)
|
|
||||||
{
|
|
||||||
local size = 0;
|
|
||||||
|
|
||||||
if (number == 0)
|
|
||||||
return 1;
|
|
||||||
loop
|
|
||||||
{
|
|
||||||
if (number == 0)
|
|
||||||
return (size);
|
|
||||||
number = number / 10;
|
|
||||||
size = size + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ntoa_s(number)
|
ntoa_s(number)
|
||||||
{
|
{
|
||||||
local str, sign, size;
|
local str, sign, size;
|
||||||
@ -24,7 +9,7 @@ ntoa_s(number)
|
|||||||
}
|
}
|
||||||
size = ntoa_get_size(number);
|
size = ntoa_get_size(number);
|
||||||
if (sign)
|
if (sign)
|
||||||
size = size + 1;
|
size++;
|
||||||
str = galloc(size + 1);
|
str = galloc(size + 1);
|
||||||
if (str == 0)
|
if (str == 0)
|
||||||
return (0);
|
return (0);
|
||||||
@ -39,6 +24,6 @@ ntoa_s(number)
|
|||||||
return (str);
|
return (str);
|
||||||
[str + size - 1] = number % 10 + '0';
|
[str + size - 1] = number % 10 + '0';
|
||||||
number = number / 10;
|
number = number / 10;
|
||||||
size = size - 1;
|
size--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
putstr(str)
|
putstr(str)
|
||||||
{
|
{
|
||||||
local i = 0;
|
local tmp = str;
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
putstr("(null)");
|
putstr("(null)");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
if ([str + i] == 0)
|
if ([tmp] == 0)
|
||||||
return str;
|
return str;
|
||||||
putchar([str + i]);
|
putchar([tmp]);
|
||||||
i = i + 1;
|
tmp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ puttab_str(tab)
|
|||||||
putchar('"');
|
putchar('"');
|
||||||
putstr([tab]);
|
putstr([tab]);
|
||||||
putchar('"');
|
putchar('"');
|
||||||
tab = tab + 1;
|
tab++;
|
||||||
if ([tab] != 0)
|
if ([tab] != 0)
|
||||||
putstr(", ");
|
putstr(", ");
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
replace(str, fill, start, stop)
|
replace_index(str, fill, start, stop)
|
||||||
{
|
{
|
||||||
local out;
|
local out;
|
||||||
local sum;
|
local sum;
|
@ -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++;
|
|
||||||
}
|
|
||||||
}
|
|
5
test.sh
5
test.sh
@ -6,7 +6,12 @@ tester()
|
|||||||
cat src/*.🗿 tests/$val.🗿 tests/test.🗿 >tmp.🗿
|
cat src/*.🗿 tests/$val.🗿 tests/test.🗿 >tmp.🗿
|
||||||
golemc tmp.🗿 > tmp.asm
|
golemc tmp.🗿 > tmp.asm
|
||||||
orgaasm tmp.asm tmp.rom
|
orgaasm tmp.asm tmp.rom
|
||||||
|
if [ -f tests/$val.input ]
|
||||||
|
then
|
||||||
|
orgaemu tmp.rom < tests/$val.input
|
||||||
|
else
|
||||||
orgaemu tmp.rom
|
orgaemu tmp.rom
|
||||||
|
fi
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
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,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
|
||||||
|
```
|
Reference in New Issue
Block a user