String support and more run-time routines
This is a work in progress.
This commit is contained in:
@@ -204,6 +204,27 @@ getcc() {
|
|||||||
error('cc');
|
error('cc');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getstr() {
|
||||||
|
auto i, c, d;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
loop:
|
||||||
|
if ((c = mapch('"')) < 0) {
|
||||||
|
number(2048);
|
||||||
|
write('*n');
|
||||||
|
return(i);
|
||||||
|
}
|
||||||
|
if ((d = mapch('"')) < 0) {
|
||||||
|
number(c*512+4);
|
||||||
|
write('*n');
|
||||||
|
return(i);
|
||||||
|
}
|
||||||
|
number(c*512+d);
|
||||||
|
write('*n');
|
||||||
|
i = i+1;
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
|
|
||||||
mapch(c) {
|
mapch(c) {
|
||||||
extrn peekc;
|
extrn peekc;
|
||||||
auto a;
|
auto a;
|
||||||
@@ -262,6 +283,21 @@ case21:
|
|||||||
goto loop;
|
goto loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (o==122) { /* string */
|
||||||
|
write('x ');
|
||||||
|
write('.+');
|
||||||
|
write('2*n');
|
||||||
|
write('t ');
|
||||||
|
write('2f');
|
||||||
|
write('*n');
|
||||||
|
write('.+');
|
||||||
|
write('1*n');
|
||||||
|
getstr();
|
||||||
|
write('2:');
|
||||||
|
write('*n');
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
|
|
||||||
if (o==20) { /* name */
|
if (o==20) { /* name */
|
||||||
if (*csym==0) { /* not seen */
|
if (*csym==0) { /* not seen */
|
||||||
if ((peeksym=symbol())==6) { /* ( */
|
if ((peeksym=symbol())==6) { /* ( */
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/* brtb.b - B run-time library */
|
||||||
|
|
||||||
|
char(s, n) {
|
||||||
|
if (n & 1) return ((s[n/2]/512) & 0777);
|
||||||
|
return(s[n/2] & 0777);
|
||||||
|
}
|
||||||
|
|
||||||
|
lchar(s, n, c) {
|
||||||
|
if (n & 1) s[n/2] = (s[n/2] & 0777) | (c*512);
|
||||||
|
else s[n/2] = (s[n/2] & 0777000) | c;
|
||||||
|
}
|
||||||
|
|
||||||
|
putstr(s) {
|
||||||
|
auto c, i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while ((c = char(s,i)) != '*e') {
|
||||||
|
putchr(c);
|
||||||
|
i = i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
getstr(s) {
|
||||||
|
auto c, i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while ((c = getch()) != '*n' & c != '*e') {
|
||||||
|
lchar(s,i,c);
|
||||||
|
i = i+1;
|
||||||
|
}
|
||||||
|
lchar(s,i,'*e');
|
||||||
|
return(s);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
putnum(n) {
|
||||||
|
if (n > 9) {
|
||||||
|
putnum(n / 10);
|
||||||
|
n = n % 10;
|
||||||
|
}
|
||||||
|
putchr(n + '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(fmt,x1,x2,x3,x4,x5,x6,x7,x8,x9) {
|
||||||
|
auto adx, c, i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
adx = &x1;
|
||||||
|
loop:
|
||||||
|
while ((c = char(fmt,i)) != '%') {
|
||||||
|
if (c=='*e')
|
||||||
|
return;
|
||||||
|
putchr(c);
|
||||||
|
i = i+1;
|
||||||
|
}
|
||||||
|
i = i+1;
|
||||||
|
c = char(fmt,i);
|
||||||
|
if (c=='d') {
|
||||||
|
if (*adx < 0) {
|
||||||
|
putchr('-');
|
||||||
|
*adx = -*adx;
|
||||||
|
}
|
||||||
|
putnum(*adx);
|
||||||
|
} else if (c=='c')
|
||||||
|
putchr(*adx);
|
||||||
|
else if (c=='s')
|
||||||
|
putstr(*adx);
|
||||||
|
else {
|
||||||
|
putchr('%');
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
|
i = i+1;
|
||||||
|
adx = adx+1;
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
+5
-3
@@ -1,8 +1,9 @@
|
|||||||
/* test.b - test program for B run-time library brt.s
|
/* test.b - test program for B run-time library brt.s brtb.b
|
||||||
|
|
||||||
b test.b test.s
|
b test.b test.s
|
||||||
|
b brtb.b brtb.s
|
||||||
echo abcABC > abc
|
echo abcABC > abc
|
||||||
perl as7 --out test.out brt.s test.s bi.s
|
perl as7 --out test.out brt.s brtb.s test.s bi.s
|
||||||
perl a7out test.out
|
perl a7out test.out
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10,7 +11,8 @@ main {
|
|||||||
extrn fname, fin;
|
extrn fname, fin;
|
||||||
auto ch;
|
auto ch;
|
||||||
|
|
||||||
fin = open(fname, 0);
|
/* fin = open(fname, 0); */
|
||||||
|
fin = open("abc ", 0);
|
||||||
|
|
||||||
goto loop;
|
goto loop;
|
||||||
while (ch != 04) {
|
while (ch != 04) {
|
||||||
|
|||||||
@@ -260,6 +260,27 @@ void getcc() {
|
|||||||
error('cc');
|
error('cc');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getstr() {
|
||||||
|
auto i, c, d;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
loop:
|
||||||
|
if ((c = mapch('"')) < 0) {
|
||||||
|
number(2048);
|
||||||
|
write('\n');
|
||||||
|
return(i);
|
||||||
|
}
|
||||||
|
if ((d = mapch('"')) < 0) {
|
||||||
|
number(c*512+4);
|
||||||
|
write('\n');
|
||||||
|
return(i);
|
||||||
|
}
|
||||||
|
number(c*512+d);
|
||||||
|
write('\n');
|
||||||
|
i = i+1;
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
|
|
||||||
mapch(c) {
|
mapch(c) {
|
||||||
extern peekc;
|
extern peekc;
|
||||||
auto a;
|
auto a;
|
||||||
@@ -318,6 +339,21 @@ case21:
|
|||||||
goto loop;
|
goto loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (o==122) { /* string */
|
||||||
|
write('x ');
|
||||||
|
write('.+');
|
||||||
|
write('2\n');
|
||||||
|
write('t ');
|
||||||
|
write('2f');
|
||||||
|
write('\n');
|
||||||
|
write('.+');
|
||||||
|
write('1\n');
|
||||||
|
getstr();
|
||||||
|
write('2:');
|
||||||
|
write('\n');
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
|
|
||||||
if (o==20) { /* name */
|
if (o==20) { /* name */
|
||||||
if (*csym==0) { /* not seen */
|
if (*csym==0) { /* not seen */
|
||||||
if ((peeksym=symbol())==6) { /* ( */
|
if ((peeksym=symbol())==6) { /* ( */
|
||||||
|
|||||||
Reference in New Issue
Block a user