From f821e3c7c3a309ebdc1e3dbf4026b41c54e99d28 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 5 May 2009 16:53:46 -0700 Subject: [PATCH] 6g tweaks * byteastring is no longer used * do not generate ODCL, OAS for globals (wasn't generating any code but might save one or two init functions) * do not call self from Init function R=ken OCL=28309 CL=28309 --- src/cmd/gc/builtin.c.boot | 1 - src/cmd/gc/dcl.c | 10 +++++++--- src/cmd/gc/go.y | 16 ++++++++++++---- src/cmd/gc/sys.go | 1 - src/runtime/string.c | 8 -------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/cmd/gc/builtin.c.boot b/src/cmd/gc/builtin.c.boot index 81ec84c370..d935fc564f 100644 --- a/src/cmd/gc/builtin.c.boot +++ b/src/cmd/gc/builtin.c.boot @@ -18,7 +18,6 @@ char *sysimport = "func sys.slicestring (? string, ? int, ? int) (? string)\n" "func sys.indexstring (? string, ? int) (? uint8)\n" "func sys.intstring (? int64) (? string)\n" - "func sys.byteastring (? *uint8, ? int) (? string)\n" "func sys.arraystring (? []uint8) (? string)\n" "func sys.stringiter (? string, ? int) (? int)\n" "func sys.stringiter2 (? string, ? int) (retk int, retv int)\n" diff --git a/src/cmd/gc/dcl.c b/src/cmd/gc/dcl.c index d39b893a35..2426fcac02 100644 --- a/src/cmd/gc/dcl.c +++ b/src/cmd/gc/dcl.c @@ -38,7 +38,8 @@ dodclvar(Node *n, Type *t) addvar(n, t, dclcontext); autoexport(n->sym); - addtop = list(addtop, nod(ODCL, n, N)); + if(funcdepth > 0) + addtop = list(addtop, nod(ODCL, n, N)); } void @@ -1299,7 +1300,7 @@ fninit(Node *n) Node *done; Node *a, *fn, *r; uint32 h; - Sym *s; + Sym *s, *initsym; if(strcmp(package, "PACKAGE") == 0) { // sys.go or unsafe.go during compiler build @@ -1329,7 +1330,8 @@ fninit(Node *n) snprint(namebuf, sizeof(namebuf), "init"); fn = nod(ODCLFUNC, N, N); - fn->nname = newname(lookup(namebuf)); + initsym = lookup(namebuf); + fn->nname = newname(initsym); fn->type = functype(N, N, N); funchdr(fn); @@ -1350,6 +1352,8 @@ fninit(Node *n) continue; if(s->oname == N) continue; + if(s == initsym) + continue; // could check that it is fn of no args/returns a = nod(OCALL, s->oname, N); diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index 4c326f1e72..e5b808460a 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -299,8 +299,12 @@ Avardcl: $$ = rev($1); dodclvar($$, $2); - $$ = nod(OAS, $$, N); - addtotop($$); + if(funcdepth == 0) { + $$ = N; + } else { + $$ = nod(OAS, $$, N); + addtotop($$); + } } Bvardcl: @@ -309,8 +313,12 @@ Bvardcl: $$ = rev($1); dodclvar($$, $2); - $$ = nod(OAS, $$, N); - addtotop($$); + if(funcdepth == 0) { + $$ = N; + } else { + $$ = nod(OAS, $$, N); + addtotop($$); + } } | new_name_list_r type '=' expr_list { diff --git a/src/cmd/gc/sys.go b/src/cmd/gc/sys.go index 6a0a6b3495..9c2bc4d04f 100644 --- a/src/cmd/gc/sys.go +++ b/src/cmd/gc/sys.go @@ -27,7 +27,6 @@ func cmpstring(string, string) int; func slicestring(string, int, int) string; func indexstring(string, int) byte; func intstring(int64) string; -func byteastring(*byte, int) string; func arraystring([]byte) string; func stringiter(string, int) int; func stringiter2(string, int) (retk int, retv int); diff --git a/src/runtime/string.c b/src/runtime/string.c index c62731ea31..667828d66e 100644 --- a/src/runtime/string.c +++ b/src/runtime/string.c @@ -173,14 +173,6 @@ sys·intstring(int64 v, String s) FLUSH(&s); } -void -sys·byteastring(byte *a, int32 l, String s) -{ - s = gostringsize(l); - mcpy(s.str, a, l); - FLUSH(&s); -} - void sys·arraystring(Array b, String s) {