Cleaned up B run-time
Pared down the B run-time to a minimal functionality. This is based on research decompiling the pdp-11 libb.a run-time.
This commit is contained in:
+2
-2
@@ -112,7 +112,7 @@ jmp start
|
|||||||
isz sp
|
isz sp
|
||||||
jmp fetch
|
jmp fetch
|
||||||
|
|
||||||
.getchr: .+1
|
.getchar: .+1
|
||||||
s 2
|
s 2
|
||||||
n 8
|
n 8
|
||||||
n 7
|
n 7
|
||||||
@@ -125,7 +125,7 @@ jmp start
|
|||||||
isz sp
|
isz sp
|
||||||
jmp fetch
|
jmp fetch
|
||||||
|
|
||||||
.putchr: .+1
|
.putchar: .+1
|
||||||
s 2
|
s 2
|
||||||
n 8
|
n 8
|
||||||
n 7
|
n 7
|
||||||
|
|||||||
+29
-49
@@ -11,46 +11,25 @@ lchar(s, n, c) {
|
|||||||
return(c);
|
return(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
getstr(s) {
|
putnum(n, b) {
|
||||||
auto c, i;
|
auto a, d;
|
||||||
|
|
||||||
i = 0;
|
d = 0;
|
||||||
while ((c = getchr()) != '*n') {
|
if (n < 0) {
|
||||||
lchar(s,i,c);
|
n = -n;
|
||||||
i = i+1;
|
if (n < 0) {
|
||||||
|
n = n-1;
|
||||||
|
d = 1;
|
||||||
|
} else
|
||||||
|
putchar('-');
|
||||||
}
|
}
|
||||||
lchar(s,i,'*e');
|
if (a = n/b)
|
||||||
return(s);
|
putnum(a, b);
|
||||||
}
|
putchar(n%b + '0' + d);
|
||||||
|
|
||||||
putstr(s) {
|
|
||||||
auto c, i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while ((c = char(s,i)) != '*e') {
|
|
||||||
putchr(c);
|
|
||||||
i = i+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
putnum(n) {
|
|
||||||
if (n > 9) {
|
|
||||||
putnum(n / 10);
|
|
||||||
n = n % 10;
|
|
||||||
}
|
|
||||||
putchr(n + '0');
|
|
||||||
}
|
|
||||||
|
|
||||||
octal(n) {
|
|
||||||
if (n > 7) {
|
|
||||||
octal(n / 8);
|
|
||||||
n = n & 7;
|
|
||||||
}
|
|
||||||
putchr(n + '0');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(fmt,x1,x2,x3,x4,x5,x6,x7,x8,x9) {
|
printf(fmt,x1,x2,x3,x4,x5,x6,x7,x8,x9) {
|
||||||
auto adx, c, i;
|
auto adx, a, c, i, n;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
adx = &x1;
|
adx = &x1;
|
||||||
@@ -58,25 +37,26 @@ loop:
|
|||||||
while ((c = char(fmt, i)) != '%') {
|
while ((c = char(fmt, i)) != '%') {
|
||||||
if (c == '*e')
|
if (c == '*e')
|
||||||
return;
|
return;
|
||||||
putchr(c);
|
putchar(c);
|
||||||
i = i+1;
|
i = i+1;
|
||||||
}
|
}
|
||||||
i = i+1;
|
i = i+1;
|
||||||
|
a = *adx;
|
||||||
c = char(fmt, i);
|
c = char(fmt, i);
|
||||||
if (c=='d') {
|
if (c=='d')
|
||||||
if (*adx < 0) {
|
putnum(a, 10);
|
||||||
putchr('-');
|
else if (c=='o')
|
||||||
*adx = -*adx;
|
putnum(a, 8);
|
||||||
}
|
|
||||||
putnum(*adx);
|
|
||||||
} else if (c=='o')
|
|
||||||
octal(*adx);
|
|
||||||
else if (c=='c')
|
else if (c=='c')
|
||||||
putchr(*adx);
|
putchar(a);
|
||||||
else if (c=='s')
|
else if (c=='s') {
|
||||||
putstr(*adx);
|
n = 0;
|
||||||
else {
|
while ((c = char(a, n)) != '*e') {
|
||||||
putchr('%');
|
putchar(c);
|
||||||
|
n = n+1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
putchar('%');
|
||||||
goto loop;
|
goto loop;
|
||||||
}
|
}
|
||||||
i = i+1;
|
i = i+1;
|
||||||
|
|||||||
Reference in New Issue
Block a user