Allow separate compilation of B files
Label namespace change so that separate compilation of multiple B files is possible.
This commit is contained in:
+27
-21
@@ -268,8 +268,8 @@ case21:
|
|||||||
*csym = 6; /* extrn */
|
*csym = 6; /* extrn */
|
||||||
} else {
|
} else {
|
||||||
*csym = 2; /* internal */
|
*csym = 2; /* internal */
|
||||||
isn = isn+1;
|
|
||||||
csym[1] = isn;
|
csym[1] = isn;
|
||||||
|
isn = isn+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*csym==5) /* auto */
|
if (*csym==5) /* auto */
|
||||||
@@ -280,7 +280,8 @@ case21:
|
|||||||
write('.');
|
write('.');
|
||||||
name(csym+2);
|
name(csym+2);
|
||||||
} else { /* internal */
|
} else { /* internal */
|
||||||
write('l');
|
write('1f');
|
||||||
|
write('+');
|
||||||
number(csym[1]);
|
number(csym[1]);
|
||||||
}
|
}
|
||||||
write('*n');
|
write('*n');
|
||||||
@@ -587,14 +588,14 @@ next:
|
|||||||
|
|
||||||
if (cval==12) { /* if */
|
if (cval==12) { /* if */
|
||||||
pexpr();
|
pexpr();
|
||||||
isn = isn+1;
|
|
||||||
o1 = isn;
|
o1 = isn;
|
||||||
|
isn = isn+1;
|
||||||
jumpc(o1);
|
jumpc(o1);
|
||||||
stmt();
|
stmt();
|
||||||
o = symbol();
|
o = symbol();
|
||||||
if (o==19 & cval==14) { /* else */
|
if (o==19 & cval==14) { /* else */
|
||||||
isn = isn+1;
|
|
||||||
o2 = isn;
|
o2 = isn;
|
||||||
|
isn = isn+1;
|
||||||
jump(o2);
|
jump(o2);
|
||||||
label(o1);
|
label(o1);
|
||||||
stmt();
|
stmt();
|
||||||
@@ -607,12 +608,12 @@ next:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cval==13) { /* while */
|
if (cval==13) { /* while */
|
||||||
isn = isn+1;
|
|
||||||
o1 = isn;
|
o1 = isn;
|
||||||
|
isn = isn+1;
|
||||||
label(o1);
|
label(o1);
|
||||||
pexpr();
|
pexpr();
|
||||||
isn = isn+1;
|
|
||||||
o2 = isn;
|
o2 = isn;
|
||||||
|
isn = isn+1;
|
||||||
jumpc(o2);
|
jumpc(o2);
|
||||||
stmt();
|
stmt();
|
||||||
jump(o1);
|
jump(o1);
|
||||||
@@ -628,8 +629,8 @@ next:
|
|||||||
peekc = 0;
|
peekc = 0;
|
||||||
if (!*csym) {
|
if (!*csym) {
|
||||||
*csym = 2; /* param */
|
*csym = 2; /* param */
|
||||||
isn = isn+1;
|
|
||||||
csym[1] = isn;
|
csym[1] = isn;
|
||||||
|
isn = isn+1;
|
||||||
} else if (*csym != 2) {
|
} else if (*csym != 2) {
|
||||||
error('rd');
|
error('rd');
|
||||||
goto next;
|
goto next;
|
||||||
@@ -653,17 +654,20 @@ syntax:
|
|||||||
}
|
}
|
||||||
|
|
||||||
blkend() {
|
blkend() {
|
||||||
extrn isn, nisn;
|
extrn isn;
|
||||||
|
auto i;
|
||||||
|
|
||||||
while (nisn < isn) {
|
if (!isn)
|
||||||
nisn = nisn+1;
|
return;
|
||||||
|
write('1:');
|
||||||
|
i = 0;
|
||||||
|
while (i < isn) {
|
||||||
write('l');
|
write('l');
|
||||||
number(nisn);
|
number(i);
|
||||||
write(':');
|
|
||||||
write('ll');
|
|
||||||
number(nisn);
|
|
||||||
write('*n');
|
write('*n');
|
||||||
|
i = i+1;
|
||||||
}
|
}
|
||||||
|
isn = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gen(o,n) {
|
gen(o,n) {
|
||||||
@@ -675,22 +679,25 @@ gen(o,n) {
|
|||||||
|
|
||||||
jumpc(n) {
|
jumpc(n) {
|
||||||
write('f '); /* ifop */
|
write('f '); /* ifop */
|
||||||
write('l');
|
write('1f');
|
||||||
|
write('+');
|
||||||
number(n);
|
number(n);
|
||||||
write('*n');
|
write('*n');
|
||||||
}
|
}
|
||||||
|
|
||||||
jump(n) {
|
jump(n) {
|
||||||
write('t '); /* traop */
|
write('x ');
|
||||||
write('ll');
|
write('1f');
|
||||||
|
write('+');
|
||||||
number(n);
|
number(n);
|
||||||
write('*n');
|
gen('*nn',6); /* goto */
|
||||||
}
|
}
|
||||||
|
|
||||||
label(n) {
|
label(n) {
|
||||||
write('ll');
|
write('l');
|
||||||
number(n);
|
number(n);
|
||||||
write(':');
|
write('=.');
|
||||||
|
write('*n');
|
||||||
}
|
}
|
||||||
|
|
||||||
printn(n) {
|
printn(n) {
|
||||||
@@ -778,6 +785,5 @@ csym;
|
|||||||
ns;
|
ns;
|
||||||
cval;
|
cval;
|
||||||
isn;
|
isn;
|
||||||
nisn;
|
|
||||||
nerror;
|
nerror;
|
||||||
nauto;
|
nauto;
|
||||||
|
|||||||
@@ -53,19 +53,19 @@ xflush() {
|
|||||||
#define flush xflush
|
#define flush xflush
|
||||||
|
|
||||||
main(int argc, char **argv) {
|
main(int argc, char **argv) {
|
||||||
extern symtab[], eof, *ns;
|
extern symtab[], eof, *ns, nerror;
|
||||||
extern fin, fout;
|
extern fin, fout;
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
if ((fout = creat(argv[2], 0777))<0) {
|
if ((fout = creat(argv[2], 0777))<0) {
|
||||||
error('fo');
|
error('fo');
|
||||||
return 1;
|
return(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((fin = open(argv[1],0))<0) {
|
if ((fin = open(argv[1],0))<0) {
|
||||||
error('fi');
|
error('fi');
|
||||||
return 1;
|
return(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ main(int argc, char **argv) {
|
|||||||
extdef();
|
extdef();
|
||||||
blkend();
|
blkend();
|
||||||
}
|
}
|
||||||
return 0;
|
return(nerror!=0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int *lookup() {
|
int *lookup() {
|
||||||
@@ -316,8 +316,8 @@ case21:
|
|||||||
*csym = 6; /* extrn */
|
*csym = 6; /* extrn */
|
||||||
} else {
|
} else {
|
||||||
*csym = 2; /* internal */
|
*csym = 2; /* internal */
|
||||||
isn = isn+1;
|
|
||||||
csym[1] = isn;
|
csym[1] = isn;
|
||||||
|
isn = isn+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*csym==5) /* auto */
|
if (*csym==5) /* auto */
|
||||||
@@ -328,7 +328,8 @@ case21:
|
|||||||
write('.');
|
write('.');
|
||||||
name(csym+2);
|
name(csym+2);
|
||||||
} else { /* internal */
|
} else { /* internal */
|
||||||
write('l');
|
write('1f');
|
||||||
|
write('+');
|
||||||
number(csym[1]);
|
number(csym[1]);
|
||||||
}
|
}
|
||||||
write('\n');
|
write('\n');
|
||||||
@@ -635,14 +636,14 @@ next:
|
|||||||
|
|
||||||
if (cval==12) { /* if */
|
if (cval==12) { /* if */
|
||||||
pexpr();
|
pexpr();
|
||||||
isn = isn+1;
|
|
||||||
o1 = isn;
|
o1 = isn;
|
||||||
|
isn = isn+1;
|
||||||
jumpc(o1);
|
jumpc(o1);
|
||||||
stmt();
|
stmt();
|
||||||
o = symbol();
|
o = symbol();
|
||||||
if (o==19 & cval==14) { /* else */
|
if (o==19 & cval==14) { /* else */
|
||||||
isn = isn+1;
|
|
||||||
o2 = isn;
|
o2 = isn;
|
||||||
|
isn = isn+1;
|
||||||
jump(o2);
|
jump(o2);
|
||||||
label(o1);
|
label(o1);
|
||||||
stmt();
|
stmt();
|
||||||
@@ -655,12 +656,12 @@ next:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cval==13) { /* while */
|
if (cval==13) { /* while */
|
||||||
isn = isn+1;
|
|
||||||
o1 = isn;
|
o1 = isn;
|
||||||
|
isn = isn+1;
|
||||||
label(o1);
|
label(o1);
|
||||||
pexpr();
|
pexpr();
|
||||||
isn = isn+1;
|
|
||||||
o2 = isn;
|
o2 = isn;
|
||||||
|
isn = isn+1;
|
||||||
jumpc(o2);
|
jumpc(o2);
|
||||||
stmt();
|
stmt();
|
||||||
jump(o1);
|
jump(o1);
|
||||||
@@ -676,8 +677,8 @@ next:
|
|||||||
peekc = 0;
|
peekc = 0;
|
||||||
if (!*csym) {
|
if (!*csym) {
|
||||||
*csym = 2; /* param */
|
*csym = 2; /* param */
|
||||||
isn = isn+1;
|
|
||||||
csym[1] = isn;
|
csym[1] = isn;
|
||||||
|
isn = isn+1;
|
||||||
} else if (*csym != 2) {
|
} else if (*csym != 2) {
|
||||||
error('rd');
|
error('rd');
|
||||||
goto next;
|
goto next;
|
||||||
@@ -701,17 +702,20 @@ syntax:
|
|||||||
}
|
}
|
||||||
|
|
||||||
blkend() {
|
blkend() {
|
||||||
extern isn, nisn;
|
extern isn;
|
||||||
|
auto i;
|
||||||
|
|
||||||
while (nisn < isn) {
|
if (!isn)
|
||||||
nisn = nisn+1;
|
return;
|
||||||
|
write('1:');
|
||||||
|
i = 0;
|
||||||
|
while (i < isn) {
|
||||||
write('l');
|
write('l');
|
||||||
number(nisn);
|
number(i);
|
||||||
write(':');
|
|
||||||
write('ll');
|
|
||||||
number(nisn);
|
|
||||||
write('\n');
|
write('\n');
|
||||||
|
i = i+1;
|
||||||
}
|
}
|
||||||
|
isn = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gen(o,n) {
|
gen(o,n) {
|
||||||
@@ -723,22 +727,25 @@ gen(o,n) {
|
|||||||
|
|
||||||
jumpc(n) {
|
jumpc(n) {
|
||||||
write('f '); /* ifop */
|
write('f '); /* ifop */
|
||||||
write('l');
|
write('1f');
|
||||||
|
write('+');
|
||||||
number(n);
|
number(n);
|
||||||
write('\n');
|
write('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
jump(n) {
|
jump(n) {
|
||||||
write('t '); /* traop */
|
write('x ');
|
||||||
write('ll');
|
write('1f');
|
||||||
|
write('+');
|
||||||
number(n);
|
number(n);
|
||||||
write('\n');
|
gen('\nn',6); /* goto */
|
||||||
}
|
}
|
||||||
|
|
||||||
label(n) {
|
label(n) {
|
||||||
write('ll');
|
write('l');
|
||||||
number(n);
|
number(n);
|
||||||
write(':');
|
write('=.');
|
||||||
|
write('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
printn(n) {
|
printn(n) {
|
||||||
@@ -826,6 +833,5 @@ int *csym;
|
|||||||
int *ns;
|
int *ns;
|
||||||
int cval;
|
int cval;
|
||||||
int isn;
|
int isn;
|
||||||
int nisn;
|
|
||||||
int nerror;
|
int nerror;
|
||||||
int nauto;
|
int nauto;
|
||||||
|
|||||||
Reference in New Issue
Block a user