Compare commits

..

No commits in common. "1452a70b85ffeeb5ebc8a7ad0ab289a9069c7b46" and "ee80b05d103bceb5c4d164c969c6a3ae8b192a11" have entirely different histories.

20 changed files with 73 additions and 132 deletions

View File

@ -1,16 +1,18 @@
aton(str) aton(str)
{ {
local i = 0;
local out = 0; local out = 0;
loop { loop {
if ([str] != '+') if ([str + i] != '+')
break; break;
str++; i++;
} }
loop { loop {
if ([str] == 0 | isdigit([str]) == 0) if ([str + i] == 0 | isdigit([str + i]) == 0)
break;
out = out * 10 + [str + i] - '0';
i++;
}
return out; return out;
out = out * 10 + [str] - '0';
str++;
}
} }

View File

@ -1,19 +1,23 @@
aton_s(str) aton_s(str)
{ {
local i = 0;
local sign = 0; local sign = 0;
local out = 0; local out = 0;
loop { loop {
if ([str] == '-') if ([str + i] == '-')
sign = sign == 0; sign = sign == 0;
else if ([str] != '+') else if ([str + i] != '+')
break; break;
str++; i++;
} }
loop { loop {
if ([str] == 0 | isdigit([str]) == 0) if ([str + i] == 0 | isdigit([str + i]) == 0)
return (sign * (0 - out)) | ((sign == 0) * out); break;
out = out * 10 + [str] - '0'; out = out * 10 + [str + i] - '0';
str++; i++;
} }
if (sign)
return (0 - out);
return out;
} }

View File

@ -1 +1 @@
bzero(tab, size) => memset(tab, size, 0); bzero(tab, size) memset(tab, size, 0);

View File

@ -1,11 +1,14 @@
contain_only(to_big, to_find) contain_only(to_big, to_find)
{ {
local tmp;
tmp = to_big;
loop loop
{ {
if ([to_big] == 0) if ([tmp] == 0)
return 1; return 1;
if (strchr(to_find, [to_big]) == 0) if (strchr(to_find, [tmp]) == 0)
return 0; return 0;
to_big++; tmp++;
} }
} }

View File

@ -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); free(tab);
} }

View File

@ -1,4 +1,4 @@
define HEAP_SIZE = 0x4000; define HEAP_SIZE = 0x8000;
global heap[HEAP_SIZE] = 0; global heap[HEAP_SIZE] = 0;
define PADDING_SIZE = 4; define PADDING_SIZE = 4;

View File

@ -3,13 +3,11 @@ geadline(prompt) {
size = 0, size = 0,
i = 0, i = 0,
c, c,
a,
buf = galloc(capacity); buf = galloc(capacity);
if (prompt) if (prompt)
putstr(prompt); putstr(prompt);
if (buf == NULL) if (buf == NULL)
return NULL; return NULL;
[buf] = 0;
loop { loop {
red &c; red &c;
@ -18,94 +16,34 @@ geadline(prompt) {
free(buf); free(buf);
return 0; return 0;
} }
} else if (c == 0x1b) { } else if (c == 0x007f) {
// ESC code if (size) {
red &c; // skip [
red &c; // 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; size = size - 1;
i = i - 1; i = i - 1;
[buf + size] = 0; [buf + size] = 0;
wrt '\r'; wrt 0x1b;
if (prompt) wrt 0x5b;
putstr(prompt); wrt 0x44;
putstr(buf);
wrt ' '; wrt ' ';
esccode('D'); wrt 0x1b;
a = size - i; wrt 0x5b;
loop { wrt 0x44;
if (a == 0)
break;
a = a - 1;
esccode('D');
}
} }
} else { } else {
size = size + 1; size = size + 1;
if (size >= capacity) { if (size > capacity) {
buf = realloc(buf, capacity * 2); buf = realloc(buf, capacity * 2);
if (buf == NULL) if (buf == NULL)
return NULL; return NULL;
capacity = capacity * 2; 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 + 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; i = i + 1;
[buf + i] = 0;
wrt c;
if (c == '\n') if (c == '\n')
return buf; return buf;
} }
} }
} }
esccode(c) {
wrt 0x1b;
wrt '[';
wrt c;
}

View File

@ -1 +1 @@
isalpha(c) => (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z'); isalpha(c) return (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z');

View File

@ -1 +1 @@
isascii(c) => c < 128; isascii(c) return c < 128;

View File

@ -1 +1 @@
isdigit(c) => c >= '0' & c <= '9'; isdigit(c) return c >= '0' & c <= '9';

View File

@ -1 +1 @@
isalnum(c) => isalpha(c) | isdigit(c); isalnum(c) return isalpha(c) | isdigit(c);

View File

@ -1 +1 @@
isprint(c) => c >= ' ' & c <= '~'; isprint(c) return c >= ' ' & c <= '~';

View File

@ -5,7 +5,6 @@ memset(tab, size, value)
loop { loop {
if (i == size) if (i == size)
return (tab); return (tab);
[tab + i] = value; [tab + i++] = value;
i = i + 1;
} }
} }

View File

@ -3,13 +3,13 @@ ntoa_get_size(number)
local size = 0; local size = 0;
if (number == 0) if (number == 0)
return 1; size++;
loop loop
{ {
if (number == 0) if (number == 0)
return (size); return (size);
number = number / 10; number = number / 10;
size = size + 1; size++;
} }
} }
@ -29,8 +29,8 @@ ntoa(number)
{ {
if (number == 0) if (number == 0)
return (str); return (str);
size = size - 1; [str + size - 1] = number % 10 + '0';
[str + size] = number % 10 + '0';
number = number / 10; number = number / 10;
size--;
} }
} }

View File

@ -3,13 +3,13 @@ ntoa_get_size(number)
local size = 0; local size = 0;
if (number == 0) if (number == 0)
return 1; size++;
loop loop
{ {
if (number == 0) if (number == 0)
return (size); return (size);
number = number / 10; number = number / 10;
size = size + 1; size++;
} }
} }
@ -24,7 +24,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 +39,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--;
} }
} }

View File

@ -1,6 +1,6 @@
print_raw_bit(number) print_raw_bit(number)
{ {
local tab = get_raw_bit(number); local tab = get_raw_bit(number), i = 0;
puttab_num(tab, 16); puttab_num(tab, 16);
free(tab); free(tab);
} }

View File

@ -1,5 +1 @@
putchar(c) putchar(c) wrt c;
{
wrt c;
return c;
}

View File

@ -1,6 +1,9 @@
putnum(number) putnum(number)
{ {
local str = ntoa(number); local str;
str = ntoa(number);
if (str == 0)
return;
putstr(str); putstr(str);
free(str); free(str);
} }

View File

@ -1,14 +1,10 @@
putstr(str) putstr(str)
{ {
local i = 0; local i = 0;
if (str == NULL) {
putstr("(null)");
return NULL;
}
loop { loop {
if ([str + i] == 0) if ([str + i] == 0)
return str; return;
putchar([str + i]); putchar([str + i]);
i = i + 1; i++;
} }
} }

View File

@ -1,19 +1,20 @@
puttab_str(tab) puttab_str(tab)
{ {
local tmp = tab;
putchar('['); putchar('[');
loop loop
{ {
if ([tab] == 0) { if ([tmp] == 0)
putchar(']'); break;
return;
}
putchar('"'); putchar('"');
putstr([tab]); putstr([tmp]);
putchar('"'); putchar('"');
tab = tab + 1; if ([tmp + 1] != 0)
if ([tab] != 0)
putstr(", "); putstr(", ");
tmp++;
} }
putchar(']');
} }
puttab_num(tab, size) puttab_num(tab, size)
@ -23,13 +24,12 @@ puttab_num(tab, size)
putchar('['); putchar('[');
loop loop
{ {
if (i == size) { if (i == size)
putchar(']'); break;
return;
}
putnum([tab + i]); putnum([tab + i]);
i++; i++;
if (i != size) if (i != size)
putstr(", "); putstr(", ");
} }
putchar(']');
} }