LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #define EXTERN | |
6 #include "go.h" | 5 #include "go.h" |
7 #include "y.tab.h" | 6 #include "y.tab.h" |
8 #include <ar.h> | 7 #include <ar.h> |
9 | 8 |
10 #undef getc | 9 #undef getc |
11 #undef ungetc | 10 #undef ungetc |
12 #define getc ccgetc | 11 #define getc ccgetc |
13 #define ungetc ccungetc | 12 #define ungetc ccungetc |
14 | 13 |
15 extern int yychar; | 14 extern int yychar; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 curio.bin = Bopen(infile, OREAD); | 210 curio.bin = Bopen(infile, OREAD); |
212 if(curio.bin == nil) { | 211 if(curio.bin == nil) { |
213 print("open %s: %r\n", infile); | 212 print("open %s: %r\n", infile); |
214 errorexit(); | 213 errorexit(); |
215 } | 214 } |
216 curio.peekc = 0; | 215 curio.peekc = 0; |
217 curio.peekc1 = 0; | 216 curio.peekc1 = 0; |
218 curio.nlsemi = 0; | 217 curio.nlsemi = 0; |
219 | 218 |
220 block = 1; | 219 block = 1; |
| 220 iota = -1000000; |
221 | 221 |
222 yyparse(); | 222 yyparse(); |
223 if(nsyntaxerrors != 0) | 223 if(nsyntaxerrors != 0) |
224 errorexit(); | 224 errorexit(); |
225 | 225 |
226 linehist(nil, 0, 0); | 226 linehist(nil, 0, 0); |
227 if(curio.bin != nil) | 227 if(curio.bin != nil) |
228 Bterm(curio.bin); | 228 Bterm(curio.bin); |
229 } | 229 } |
230 testdclstack(); | 230 testdclstack(); |
(...skipping 15 matching lines...) Expand all Loading... |
246 | 246 |
247 // Phase 2: Variable assignments. | 247 // Phase 2: Variable assignments. |
248 // To check interface assignments, depends on phase 1. | 248 // To check interface assignments, depends on phase 1. |
249 for(l=xtop; l; l=l->next) | 249 for(l=xtop; l; l=l->next) |
250 if(l->n->op == ODCL || l->n->op == OAS) | 250 if(l->n->op == ODCL || l->n->op == OAS) |
251 typecheck(&l->n, Etop); | 251 typecheck(&l->n, Etop); |
252 resumetypecopy(); | 252 resumetypecopy(); |
253 resumecheckwidth(); | 253 resumecheckwidth(); |
254 | 254 |
255 // Phase 3: Type check function bodies. | 255 // Phase 3: Type check function bodies. |
256 » for(l=xtop; l; l=l->next) | 256 » for(l=xtop; l; l=l->next) { |
257 » » if(l->n->op == ODCLFUNC) { | 257 » » if(l->n->op == ODCLFUNC || l->n->op == OCLOSURE) { |
258 curfn = l->n; | 258 curfn = l->n; |
259 saveerrors(); | 259 saveerrors(); |
260 typechecklist(l->n->nbody, Etop); | 260 typechecklist(l->n->nbody, Etop); |
261 if(nerrors != 0) | 261 if(nerrors != 0) |
262 l->n->nbody = nil; // type errors; do not compi
le | 262 l->n->nbody = nil; // type errors; do not compi
le |
263 } | 263 } |
| 264 } |
| 265 |
264 curfn = nil; | 266 curfn = nil; |
| 267 ········ |
| 268 if(nsavederrors+nerrors) |
| 269 errorexit(); |
265 | 270 |
266 // Phase 3b: escape analysis. | 271 // Phase 3b: escape analysis. |
267 » if (debug['s']) { | 272 » if(debug['s']) |
268 » for(l=xtop; l; l=l->next) | 273 » » escapes(); |
269 » » if(l->n->op == ODCLFUNC) | |
270 » » » escanalfunc(l->n); | |
271 » escanalfinish(); | |
272 » } | |
273 | 274 |
274 // Phase 4: Compile function bodies. | 275 // Phase 4: Compile function bodies. |
275 for(l=xtop; l; l=l->next) | 276 for(l=xtop; l; l=l->next) |
276 if(l->n->op == ODCLFUNC) | 277 if(l->n->op == ODCLFUNC) |
277 funccompile(l->n, 0); | 278 funccompile(l->n, 0); |
278 | 279 |
279 if(nsavederrors+nerrors == 0) | 280 if(nsavederrors+nerrors == 0) |
280 fninit(xtop); | 281 fninit(xtop); |
281 | 282 |
282 // Phase 4b: Compile all closures. | 283 // Phase 4b: Compile all closures. |
283 while(closures) { | 284 while(closures) { |
284 l = closures; | 285 l = closures; |
285 closures = nil; | 286 closures = nil; |
286 » » for(; l; l=l->next) | 287 » » for(; l; l=l->next) { |
287 funccompile(l->n, 1); | 288 funccompile(l->n, 1); |
| 289 } |
288 } | 290 } |
289 | 291 |
290 // Phase 5: check external declarations. | 292 // Phase 5: check external declarations. |
291 for(l=externdcl; l; l=l->next) | 293 for(l=externdcl; l; l=l->next) |
292 if(l->n->op == ONAME) | 294 if(l->n->op == ONAME) |
293 typecheck(&l->n, Erv); | 295 typecheck(&l->n, Erv); |
294 | 296 |
295 if(nerrors+nsavederrors) | 297 if(nerrors+nsavederrors) |
296 errorexit(); | 298 errorexit(); |
297 | 299 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 snprint(namebuf, sizeof(namebuf), "%Z.a", name); | 399 snprint(namebuf, sizeof(namebuf), "%Z.a", name); |
398 if(access(namebuf, 0) >= 0) | 400 if(access(namebuf, 0) >= 0) |
399 return 1; | 401 return 1; |
400 snprint(namebuf, sizeof(namebuf), "%Z.%c", name, thechar); | 402 snprint(namebuf, sizeof(namebuf), "%Z.%c", name, thechar); |
401 if(access(namebuf, 0) >= 0) | 403 if(access(namebuf, 0) >= 0) |
402 return 1; | 404 return 1; |
403 return 0; | 405 return 0; |
404 } | 406 } |
405 | 407 |
406 // local imports should be canonicalized already. | 408 // local imports should be canonicalized already. |
407 » // don't want to see "container/../container/vector" | 409 » // don't want to see "encoding/../encoding/base64" |
408 » // as different from "container/vector". | 410 » // as different from "encoding/base64". |
409 q = mal(name->len+1); | 411 q = mal(name->len+1); |
410 memmove(q, name->s, name->len); | 412 memmove(q, name->s, name->len); |
411 q[name->len] = '\0'; | 413 q[name->len] = '\0'; |
412 cleanname(q); | 414 cleanname(q); |
413 if(strlen(q) != name->len || memcmp(q, name->s, name->len) != 0) { | 415 if(strlen(q) != name->len || memcmp(q, name->s, name->len) != 0) { |
414 yyerror("non-canonical import path %Z (should be %s)", name, q); | 416 yyerror("non-canonical import path %Z (should be %s)", name, q); |
415 return 0; | 417 return 0; |
416 } | 418 } |
417 | 419 |
418 for(p = idirs; p != nil; p = p->link) { | 420 for(p = idirs; p != nil; p = p->link) { |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 } | 734 } |
733 | 735 |
734 strlit: | 736 strlit: |
735 *(int32*)cp = clen-sizeof(int32); // length | 737 *(int32*)cp = clen-sizeof(int32); // length |
736 do { | 738 do { |
737 cp[clen++] = 0; | 739 cp[clen++] = 0; |
738 } while(clen & MAXALIGN); | 740 } while(clen & MAXALIGN); |
739 yylval.val.u.sval = (Strlit*)cp; | 741 yylval.val.u.sval = (Strlit*)cp; |
740 yylval.val.ctype = CTSTR; | 742 yylval.val.ctype = CTSTR; |
741 DBG("lex: string literal\n"); | 743 DBG("lex: string literal\n"); |
| 744 strcpy(litbuf, "string literal"); |
742 return LLITERAL; | 745 return LLITERAL; |
743 | 746 |
744 case '\'': | 747 case '\'': |
745 /* '.' */ | 748 /* '.' */ |
746 if(escchar('\'', &escflag, &v)) { | 749 if(escchar('\'', &escflag, &v)) { |
747 yyerror("empty character literal or unescaped ' in chara
cter literal"); | 750 yyerror("empty character literal or unescaped ' in chara
cter literal"); |
748 v = '\''; | 751 v = '\''; |
749 } | 752 } |
750 if(!escchar('\'', &escflag, &v)) { | 753 if(!escchar('\'', &escflag, &v)) { |
751 yyerror("missing '"); | 754 yyerror("missing '"); |
752 ungetc(v); | 755 ungetc(v); |
753 } | 756 } |
754 yylval.val.u.xval = mal(sizeof(*yylval.val.u.xval)); | 757 yylval.val.u.xval = mal(sizeof(*yylval.val.u.xval)); |
755 mpmovecfix(yylval.val.u.xval, v); | 758 mpmovecfix(yylval.val.u.xval, v); |
756 yylval.val.ctype = CTINT; | 759 yylval.val.ctype = CTINT; |
757 DBG("lex: codepoint literal\n"); | 760 DBG("lex: codepoint literal\n"); |
| 761 strcpy(litbuf, "string literal"); |
758 return LLITERAL; | 762 return LLITERAL; |
759 | 763 |
760 case '/': | 764 case '/': |
761 c1 = getc(); | 765 c1 = getc(); |
762 if(c1 == '*') { | 766 if(c1 == '*') { |
763 int nl; | 767 int nl; |
764 ························ | 768 ························ |
765 nl = 0; | 769 nl = 0; |
766 for(;;) { | 770 for(;;) { |
767 c = getr(); | 771 c = getr(); |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 ungetc(c); | 1141 ungetc(c); |
1138 | 1142 |
1139 yylval.val.u.xval = mal(sizeof(*yylval.val.u.xval)); | 1143 yylval.val.u.xval = mal(sizeof(*yylval.val.u.xval)); |
1140 mpatofix(yylval.val.u.xval, lexbuf); | 1144 mpatofix(yylval.val.u.xval, lexbuf); |
1141 if(yylval.val.u.xval->ovf) { | 1145 if(yylval.val.u.xval->ovf) { |
1142 yyerror("overflow in constant"); | 1146 yyerror("overflow in constant"); |
1143 mpmovecfix(yylval.val.u.xval, 0); | 1147 mpmovecfix(yylval.val.u.xval, 0); |
1144 } | 1148 } |
1145 yylval.val.ctype = CTINT; | 1149 yylval.val.ctype = CTINT; |
1146 DBG("lex: integer literal\n"); | 1150 DBG("lex: integer literal\n"); |
| 1151 strcpy(litbuf, "literal "); |
| 1152 strcat(litbuf, lexbuf); |
1147 return LLITERAL; | 1153 return LLITERAL; |
1148 | 1154 |
1149 casedot: | 1155 casedot: |
1150 for(;;) { | 1156 for(;;) { |
1151 if(cp+10 >= ep) { | 1157 if(cp+10 >= ep) { |
1152 yyerror("identifier too long"); | 1158 yyerror("identifier too long"); |
1153 errorexit(); | 1159 errorexit(); |
1154 } | 1160 } |
1155 *cp++ = c; | 1161 *cp++ = c; |
1156 c = getc(); | 1162 c = getc(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 *cp = 0; | 1215 *cp = 0; |
1210 yylval.val.u.cval = mal(sizeof(*yylval.val.u.cval)); | 1216 yylval.val.u.cval = mal(sizeof(*yylval.val.u.cval)); |
1211 mpmovecflt(&yylval.val.u.cval->real, 0.0); | 1217 mpmovecflt(&yylval.val.u.cval->real, 0.0); |
1212 mpatoflt(&yylval.val.u.cval->imag, lexbuf); | 1218 mpatoflt(&yylval.val.u.cval->imag, lexbuf); |
1213 if(yylval.val.u.cval->imag.val.ovf) { | 1219 if(yylval.val.u.cval->imag.val.ovf) { |
1214 yyerror("overflow in imaginary constant"); | 1220 yyerror("overflow in imaginary constant"); |
1215 mpmovecflt(&yylval.val.u.cval->real, 0.0); | 1221 mpmovecflt(&yylval.val.u.cval->real, 0.0); |
1216 } | 1222 } |
1217 yylval.val.ctype = CTCPLX; | 1223 yylval.val.ctype = CTCPLX; |
1218 DBG("lex: imaginary literal\n"); | 1224 DBG("lex: imaginary literal\n"); |
| 1225 strcpy(litbuf, "literal "); |
| 1226 strcat(litbuf, lexbuf); |
1219 return LLITERAL; | 1227 return LLITERAL; |
1220 | 1228 |
1221 caseout: | 1229 caseout: |
1222 *cp = 0; | 1230 *cp = 0; |
1223 ungetc(c); | 1231 ungetc(c); |
1224 | 1232 |
1225 yylval.val.u.fval = mal(sizeof(*yylval.val.u.fval)); | 1233 yylval.val.u.fval = mal(sizeof(*yylval.val.u.fval)); |
1226 mpatoflt(yylval.val.u.fval, lexbuf); | 1234 mpatoflt(yylval.val.u.fval, lexbuf); |
1227 if(yylval.val.u.fval->val.ovf) { | 1235 if(yylval.val.u.fval->val.ovf) { |
1228 yyerror("overflow in float constant"); | 1236 yyerror("overflow in float constant"); |
1229 mpmovecflt(yylval.val.u.fval, 0.0); | 1237 mpmovecflt(yylval.val.u.fval, 0.0); |
1230 } | 1238 } |
1231 yylval.val.ctype = CTFLT; | 1239 yylval.val.ctype = CTFLT; |
1232 DBG("lex: floating literal\n"); | 1240 DBG("lex: floating literal\n"); |
| 1241 strcpy(litbuf, "literal "); |
| 1242 strcat(litbuf, lexbuf); |
1233 return LLITERAL; | 1243 return LLITERAL; |
1234 } | 1244 } |
1235 | 1245 |
1236 /* | 1246 /* |
1237 * read and interpret syntax that looks like | 1247 * read and interpret syntax that looks like |
1238 * //line parse.y:15 | 1248 * //line parse.y:15 |
1239 * as a discontinuity in sequential line numbers. | 1249 * as a discontinuity in sequential line numbers. |
1240 * the next line of input comes from parse.y:15 | 1250 * the next line of input comes from parse.y:15 |
1241 */ | 1251 */ |
1242 static int | 1252 static int |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 s->def->sym = s; | 1739 s->def->sym = s; |
1730 } | 1740 } |
1731 | 1741 |
1732 s = lookup("false"); | 1742 s = lookup("false"); |
1733 if(s->def == N) { | 1743 if(s->def == N) { |
1734 s->def = nodbool(0); | 1744 s->def = nodbool(0); |
1735 s->def->sym = s; | 1745 s->def->sym = s; |
1736 } | 1746 } |
1737 ········ | 1747 ········ |
1738 nodfp = nod(ONAME, N, N); | 1748 nodfp = nod(ONAME, N, N); |
1739 nodfp->noescape = 1; | |
1740 nodfp->type = types[TINT32]; | 1749 nodfp->type = types[TINT32]; |
1741 nodfp->xoffset = 0; | 1750 nodfp->xoffset = 0; |
1742 nodfp->class = PPARAM; | 1751 nodfp->class = PPARAM; |
1743 nodfp->sym = lookup(".fp"); | 1752 nodfp->sym = lookup(".fp"); |
1744 } | 1753 } |
1745 | 1754 |
1746 struct | 1755 struct |
1747 { | 1756 { |
1748 int lex; | 1757 int lex; |
1749 char* name; | 1758 char* name; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 static void | 1872 static void |
1864 yytinit(void) | 1873 yytinit(void) |
1865 { | 1874 { |
1866 int i, j; | 1875 int i, j; |
1867 extern char *yytname[]; | 1876 extern char *yytname[]; |
1868 char *s, *t; | 1877 char *s, *t; |
1869 | 1878 |
1870 for(i=0; yytname[i] != nil; i++) { | 1879 for(i=0; yytname[i] != nil; i++) { |
1871 s = yytname[i]; | 1880 s = yytname[i]; |
1872 ················ | 1881 ················ |
| 1882 if(strcmp(s, "LLITERAL") == 0) { |
| 1883 strcpy(litbuf, "literal"); |
| 1884 yytname[i] = litbuf; |
| 1885 goto loop; |
| 1886 } |
| 1887 ················ |
1873 // apply yytfix if possible | 1888 // apply yytfix if possible |
1874 for(j=0; j<nelem(yytfix); j++) { | 1889 for(j=0; j<nelem(yytfix); j++) { |
1875 if(strcmp(s, yytfix[j].have) == 0) { | 1890 if(strcmp(s, yytfix[j].have) == 0) { |
1876 yytname[i] = yytfix[j].want; | 1891 yytname[i] = yytfix[j].want; |
1877 goto loop; | 1892 goto loop; |
1878 } | 1893 } |
1879 } | 1894 } |
1880 | 1895 |
1881 // turn 'x' into x. | 1896 // turn 'x' into x. |
1882 if(s[0] == '\'') { | 1897 if(s[0] == '\'') { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 p = infile; | 1952 p = infile; |
1938 else | 1953 else |
1939 p = p+1; | 1954 p = p+1; |
1940 snprint(namebuf, sizeof(namebuf), "%s", p); | 1955 snprint(namebuf, sizeof(namebuf), "%s", p); |
1941 p = strrchr(namebuf, '.'); | 1956 p = strrchr(namebuf, '.'); |
1942 if(p != nil) | 1957 if(p != nil) |
1943 *p = 0; | 1958 *p = 0; |
1944 outfile = smprint("%s.%c", namebuf, thechar); | 1959 outfile = smprint("%s.%c", namebuf, thechar); |
1945 } | 1960 } |
1946 } | 1961 } |
LEFT | RIGHT |