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:
rswier
2016-04-13 05:09:24 -04:00
parent 22f0d2e99a
commit ce6b5c4887
2 changed files with 34 additions and 54 deletions
+2 -2
View File
@@ -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
+32 -52
View File
@@ -11,72 +11,52 @@ 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;
loop: 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;
c = char(fmt,i); a = *adx;
if (c=='d') { c = char(fmt, i);
if (*adx < 0) { if (c=='d')
putchr('-'); putnum(a, 10);
*adx = -*adx; else if (c=='o')
} 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;