1
0
mirror of https://github.com/golang/go synced 2024-11-25 21:57:57 -07:00

checkpoint; still plenty to clean up

R=ken
OCL=32576
CL=32580
This commit is contained in:
Russ Cox 2009-07-31 09:29:28 -07:00
parent 9299ae461d
commit a2b8e38766
11 changed files with 491 additions and 1040 deletions

View File

@ -52,6 +52,11 @@ builtin.c: sys.go unsafe.go mkbuiltin1.c mkbuiltin
./mkbuiltin >builtin.c || \
(echo 'mkbuiltin failed; using bootstrap copy of builtin.c'; cp builtin.c.boot builtin.c)
subr.$O: opnames.h
opnames.h: mkopnames go.h
./mkopnames go.h >opnames.h
clean:
rm -f $(OFILES) *.6 enam.c 6.out a.out y.tab.h y.tab.c $(LIB) mkbuiltin1 builtin.c _builtin.c

View File

@ -4,7 +4,7 @@ char *sysimport =
"func sys.throwindex ()\n"
"func sys.throwreturn ()\n"
"func sys.throwinit ()\n"
"func sys.panicl (? int32)\n"
"func sys.panicl ()\n"
"func sys.printbool (? bool)\n"
"func sys.printfloat (? float64)\n"
"func sys.printint (? int64)\n"

View File

@ -1670,7 +1670,7 @@ variter(NodeList *vl, Node *nt, NodeList *el)
v = vl->n;
tv = t;
if(t == T) {
gettype(&e, &r);
typecheck(&e, Erv);
defaultlit(&e, T);
tv = e->type;
}

View File

@ -320,43 +320,75 @@ enum
{
OXXX,
ONAME, ONONAME, OTYPE, OPACK, OLITERAL,
ODCL,
ODOT, ODOTPTR, ODOTMETH, ODOTINTER,
ODCLFUNC, ODCLFIELD, ODCLARG,
OCMP, OPTR, OARRAY, ORANGE,
ORETURN, OFOR, OIF, OSWITCH, ODEFER,
OAS, OAS2, OASOP, OCASE, OXCASE, OFALL, OXFALL,
OGOTO, OPROC, OMAKE, ONEW, OEMPTY, OSELECT,
OLEN, OCAP, OPANIC, OPANICN, OPRINT, OPRINTN, OTYPEOF,
OCLOSE, OCLOSED, OBLOCK,
// names
ONAME,
ONONAME,
OTYPE,
OPACK,
OLITERAL,
OOROR,
OANDAND,
OEQ, ONE, OLT, OLE, OGE, OGT,
// exprs
OADD, OSUB, OOR, OXOR,
OMUL, ODIV, OMOD, OLSH, ORSH, OAND, OANDNOT,
OINC, ODEC,
OFUNC,
OLABEL,
OBREAK,
OCONTINUE,
OADDR,
OIND,
OCALL, OCALLFUNC, OCALLMETH, OCALLINTER,
OINDEX, OSLICE,
ONOT, OCOM, OPLUS, OMINUS, OSEND, ORECV,
OREGISTER, OINDREG,
OKEY, OPARAM,
OCOMPOS, OCOMPSLICE, OCOMPMAP,
OCONV, OCONVNOP, OCONVRUNE, OCONVSTRB, OCONVSTRI,
OCONVA2S,
ODOTTYPE, OTYPESW, OTYPECASE,
OANDAND,
OARRAY,
OAS, OAS2, OASOP,
OBAD,
OCALL, OCALLFUNC, OCALLMETH, OCALLINTER,
OCAP,
OCLOSE,
OCLOSED,
OCOMPOS, OCOMPSLICE, OCOMPMAP,
OCONV, OCONVNOP, OCONVRUNE, OCONVSTRB, OCONVSTRI, OCONVA2S,
ODCL, ODCLFUNC, ODCLFIELD, ODCLARG,
ODOT, ODOTPTR, ODOTMETH, ODOTINTER,
ODOTTYPE,
OEQ, ONE, OLT, OLE, OGE, OGT,
OFUNC,
OIND,
OINDEX, OINDEXSTR, OINDEXMAP, OINDEXARR,
OKEY, OPARAM,
OLEN,
OMAKE,
OMUL, ODIV, OMOD, OLSH, ORSH, OAND, OANDNOT,
ONEW,
ONOT, OCOM, OPLUS, OMINUS,
OOROR,
OPANIC, OPANICN, OPRINT, OPRINTN,
OSEND,
OSLICE, OSLICESTR, OSLICEARR,
ORECV,
OTCHAN, OTMAP, OTSTRUCT, OTINTER, OTFUNC, OTARRAY,
// stmts
OBLOCK,
OBREAK,
OCASE, OXCASE,
OCONTINUE,
ODEFER,
OEMPTY,
OFALL, OXFALL,
OFOR,
OGOTO,
OIF,
OLABEL,
OPROC,
ORANGE,
ORETURN,
OSELECT,
OSWITCH,
OTYPECASE,
OTYPESW,
OEXTEND, // 6g internal
// types
OTCHAN,
OTMAP,
OTSTRUCT,
OTINTER,
OTFUNC,
OTARRAY,
// for back ends
OCMP, ODEC, OEXTEND, OINC, OREGISTER, OINDREG,
OEND,
};
@ -936,12 +968,10 @@ Type* pkgtype(Sym*);
/*
* walk.c
*/
void gettype(Node**, NodeList**);
void walk(Node*);
void walkstmt(Node**);
void walkstmtlist(NodeList*);
void walkexpr(Node**, int, NodeList**);
void walkexprlist(NodeList*, int, NodeList**);
void walkexprlist(NodeList*, NodeList**);
void walkconv(Node**, NodeList**);
void walkdottype(Node*, NodeList**);
void walkas(Node*);
@ -949,21 +979,20 @@ void walkbool(Node**);
void walkswitch(Node*);
void walkselect(Node*);
void walkdot(Node*, NodeList**);
void walkexpr(Node**, NodeList**);
Node* ascompatee1(int, Node*, Node*, NodeList**);
NodeList* ascompatee(int, NodeList*, NodeList*, NodeList**);
NodeList* ascompatet(int, NodeList*, Type**, int, NodeList**);
NodeList* ascompatte(int, Type**, NodeList*, int, NodeList**);
int ascompat(Type*, Type*);
Node* prcompat(NodeList*, int, int);
Node* nodpanic(int32);
Node* newcompat(Node*);
Node* makecompat(Node*);
Node* stringop(Node*, int, NodeList**);
Node* stringop(Node*, NodeList**);
Type* fixmap(Type*);
Node* mapop(Node*, int, NodeList**);
Node* mapop(Node*, NodeList**);
Type* fixchan(Type*);
Node* chanop(Node*, int, NodeList**);
Node* arrayop(Node*, int);
Node* chanop(Node*, NodeList**);
Node* arrayop(Node*);
Node* ifacecvt(Type*, Node*, int);
Node* ifaceop(Node*);
int ifaceas(Type*, Type*, int);

View File

@ -16,7 +16,7 @@ rm -f _builtin.c
for i in sys unsafe
do
$GC -A $i.go
./mkbuiltin1 $i >>_builtin.c
O=$O ./mkbuiltin1 $i >>_builtin.c
done
# If _builtin.c has changed vs builtin.c.boot,

View File

@ -26,7 +26,7 @@ main(int argc, char **argv)
name = argv[1];
snprintf(initfunc, sizeof(initfunc), "init_%s_function", name);
snprintf(buf, sizeof(buf), "%s.6", name);
snprintf(buf, sizeof(buf), "%s.%s", name, getenv("O"));
if((fin = fopen(buf, "r")) == NULL) {
fprintf(stderr, "open %s: %s\n", buf, strerror(errno));
exit(1);

View File

@ -4,6 +4,7 @@
#include "go.h"
#include "y.tab.h"
#include "opnames.h"
void
errorexit(void)
@ -612,127 +613,6 @@ dump(char *s, Node *n)
dodump(n, 1);
}
/*
s%,%,\n%g
s%\n+%\n%g
s%^[ ]*O%%g
s%,.*%%g
s%.+% [O&] = "&",%g
s%^ ........*\]%&~%g
s%~ %%g
|sort
*/
static char*
opnames[] =
{
[OADDR] = "ADDR",
[OADD] = "ADD",
[OANDAND] = "ANDAND",
[OANDNOT] = "ANDNOT",
[OAND] = "AND",
[OARRAY] = "ARRAY",
[OASOP] = "ASOP",
[OAS] = "AS",
[OAS2] = "AS2",
[OBAD] = "BAD",
[OBLOCK] = "BLOCK",
[OBREAK] = "BREAK",
[OCALLFUNC] = "CALLFUNC",
[OCALLINTER] = "CALLINTER",
[OCALLMETH] = "CALLMETH",
[OCALL] = "CALL",
[OCAP] = "CAP",
[OCASE] = "CASE",
[OCLOSED] = "CLOSED",
[OCLOSE] = "CLOSE",
[OCMP] = "CMP",
[OCOMPMAP] = "COMPMAP",
[OCOMPOS] = "COMPOS",
[OCOMPSLICE] = "COMPSLICE",
[OCOM] = "COM",
[OCONTINUE] = "CONTINUE",
[OCONV] = "CONV",
[OCONVNOP] = "CONVNOP",
[ODCLARG] = "DCLARG",
[ODCLFIELD] = "DCLFIELD",
[ODCLFUNC] = "DCLFUNC",
[ODCL] = "DCL",
[ODEC] = "DEC",
[ODEFER] = "DEFER",
[ODIV] = "DIV",
[ODOTINTER] = "DOTINTER",
[ODOTMETH] = "DOTMETH",
[ODOTPTR] = "DOTPTR",
[ODOTTYPE] = "DOTTYPE",
[ODOT] = "DOT",
[OEMPTY] = "EMPTY",
[OEND] = "END",
[OEQ] = "EQ",
[OEXTEND] = "EXTEND",
[OFALL] = "FALL",
[OFOR] = "FOR",
[OFUNC] = "FUNC",
[OGE] = "GE",
[OGOTO] = "GOTO",
[OGT] = "GT",
[OIF] = "IF",
[OINC] = "INC",
[OINDEX] = "INDEX",
[OINDREG] = "INDREG",
[OIND] = "IND",
[OKEY] = "KEY",
[OLABEL] = "LABEL",
[OLEN] = "LEN",
[OLE] = "LE",
[OLITERAL] = "LITERAL",
[OLSH] = "LSH",
[OLT] = "LT",
[OMAKE] = "MAKE",
[OMINUS] = "MINUS",
[OMOD] = "MOD",
[OMUL] = "MUL",
[ONAME] = "NAME",
[ONEW] = "NEW",
[ONE] = "NE",
[ONONAME] = "NONAME",
[ONOT] = "NOT",
[OOROR] = "OROR",
[OOR] = "OR",
[OPANICN] = "PANICN",
[OPANIC] = "PANIC",
[OPACK] = "PACK",
[OPARAM] = "PARAM",
[OPLUS] = "PLUS",
[OPRINTN] = "PRINTN",
[OPRINT] = "PRINT",
[OPROC] = "PROC",
[OPTR] = "PTR",
[ORANGE] = "RANGE",
[ORECV] = "RECV",
[OREGISTER] = "REGISTER",
[ORETURN] = "RETURN",
[ORSH] = "RSH",
[OSELECT] = "SELECT",
[OSEND] = "SEND",
[OSLICE] = "SLICE",
[OSUB] = "SUB",
[OSWITCH] = "SWITCH",
[OTCHAN] = "TCHAN",
[OTMAP] = "TMAP",
[OTSTRUCT] = "TSTRUCT",
[OTINTER] = "TINTER",
[OTFUNC] = "TFUNC",
[OTARRAY] = "TARRAY",
[OTYPEOF] = "TYPEOF",
[OTYPESW] = "TYPESW",
[OTYPE] = "TYPE",
[OXCASE] = "XCASE",
[OXFALL] = "XFALL",
[OXOR] = "XOR",
[OXXX] = "XXX",
};
static char*
goopnames[] =
{
@ -2395,7 +2275,7 @@ saferef(Node *n, NodeList **init)
*r = *n;
r->left = l;
typecheck(&r, Elv);
walkexpr(&r, Elv, init);
walkexpr(&r, init);
return r;
case OINDEX:
@ -2405,11 +2285,11 @@ saferef(Node *n, NodeList **init)
tempname(l, ptrto(n->type));
a = nod(OAS, l, nod(OADDR, n, N));
typecheck(&a, Etop);
walkexpr(&a, Etop, init);
walkexpr(&a, init);
*init = list(*init, a);
r = nod(OIND, l, N);
typecheck(&r, Elv);
walkexpr(&r, Elv, init);
walkexpr(&r, init);
return r;
}
fatal("saferef %N", n);

View File

@ -250,7 +250,7 @@ sw0(Node **cp, Type *place, int arg)
yyerror("expression case in a type switch");
return T;
}
walkexpr(cp, Erv, nil);
walkexpr(cp, nil);
break;
case OTYPESW:
case OTYPECASE:
@ -596,7 +596,7 @@ exprswitch(Node *sw)
if(sw->ntest->val.u.bval == 0)
arg = Sfalse;
}
walkexpr(&sw->ntest, Erv, &sw->ninit);
walkexpr(&sw->ntest, &sw->ninit);
/*
* pass 0,1,2,3
@ -780,7 +780,7 @@ typeswitch(Node *sw)
yyerror("type switch must have an assignment");
return;
}
walkexpr(&sw->ntest->right, Erv, &sw->ninit);
walkexpr(&sw->ntest->right, &sw->ninit);
if(!istype(sw->ntest->right->type, TINTER)) {
yyerror("type switch must be on an interface");
return;

View File

@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package PACKAGE
// emitted by compiler, not referred to by go programs
@ -11,7 +10,7 @@ func mal(int32) *any;
func throwindex();
func throwreturn();
func throwinit();
func panicl(int32);
func panicl();
func printbool(bool);
func printfloat(float64);

View File

@ -315,7 +315,9 @@ reswitch:
* exprs
*/
case OADDR:
l = typecheck(&n->left, Elv);
typecheck(&n->left, Elv);
defaultlit(&n->left, T);
l = n->left;
if((t = l->type) == T)
goto error;
n->type = ptrto(t);
@ -452,6 +454,9 @@ reswitch:
break;
case TMAP:
n->etype = 0;
if(top & Elv)
n->etype = 1; // clumsy hack
ok |= Erv | Elv;
defaultlit(&n->right, t->down);
n->type = t->type;
@ -499,6 +504,9 @@ reswitch:
if((t = r->type) == T)
goto error;
// TODO: more aggressive
n->etype = 0;
if(top & Erv)
n->etype = 1; // clumsy hack
ok |= Etop | Erv;
n->type = types[TBOOL];
goto ret;
@ -539,12 +547,15 @@ reswitch:
goto error;
case TARRAY:
ok |= Elv;
n = arrayop(n, Erv);
n->type = typ(TARRAY);
n->type->type = t;
n->type->bound = -1;
n = arrayop(n);
break;
case TSTRING:
n = stringop(n, Erv, nil);
n->type = t;
n = stringop(n, nil);
break;
}
goto ret;

File diff suppressed because it is too large Load Diff