Commit f6791da7 authored by Russ Cox's avatar Russ Cox

[dev.cc] cmd/new6g etc: reconvert from C

Reconvert using rsc.io/c2go rev 27b3f59.
(Same as last conversion, but C sources have changed
due to merging master into this branch.)

Change-Id: Ib314bb9ac14a726ceb83e2ecf4d1ad2d0b331c38
Reviewed-on: https://go-review.googlesource.com/5471Reviewed-by: default avatarRob Pike <r@golang.org>
parent 1996f276
...@@ -21,6 +21,7 @@ func closurehdr(ntype *Node) { ...@@ -21,6 +21,7 @@ func closurehdr(ntype *Node) {
n = Nod(OCLOSURE, nil, nil) n = Nod(OCLOSURE, nil, nil)
n.Ntype = ntype n.Ntype = ntype
n.Funcdepth = Funcdepth n.Funcdepth = Funcdepth
n.Outerfunc = Curfn
funchdr(n) funchdr(n)
...@@ -133,7 +134,62 @@ func typecheckclosure(func_ *Node, top int) { ...@@ -133,7 +134,62 @@ func typecheckclosure(func_ *Node, top int) {
xtop = list(xtop, makeclosure(func_)) xtop = list(xtop, makeclosure(func_))
} }
var makeclosure_closgen int // closurename returns name for OCLOSURE n.
// It is not as simple as it ought to be, because we typecheck nested closures
// starting from the innermost one. So when we check the inner closure,
// we don't yet have name for the outer closure. This function uses recursion
// to generate names all the way up if necessary.
var closurename_closgen int
func closurename(n *Node) *Sym {
var outer string
var prefix string
var gen int
if n.Sym != nil {
return n.Sym
}
gen = 0
outer = ""
prefix = ""
if n.Outerfunc == nil {
// Global closure.
outer = "glob"
prefix = "func"
closurename_closgen++
gen = closurename_closgen
} else if n.Outerfunc.Op == ODCLFUNC {
// The outermost closure inside of a named function.
outer = n.Outerfunc.Nname.Sym.Name
prefix = "func"
// Yes, functions can be named _.
// Can't use function closgen in such case,
// because it would lead to name clashes.
if !isblank(n.Outerfunc.Nname) {
n.Outerfunc.Closgen++
gen = n.Outerfunc.Closgen
} else {
closurename_closgen++
gen = closurename_closgen
}
} else if n.Outerfunc.Op == OCLOSURE {
// Nested closure, recurse.
outer = closurename(n.Outerfunc).Name
prefix = ""
n.Outerfunc.Closgen++
gen = n.Outerfunc.Closgen
} else {
Fatal("closurename called for %v", Nconv(n, obj.FmtShort))
}
namebuf = fmt.Sprintf("%s.%s%d", outer, prefix, gen)
n.Sym = Lookup(namebuf)
return n.Sym
}
func makeclosure(func_ *Node) *Node { func makeclosure(func_ *Node) *Node {
var xtype *Node var xtype *Node
...@@ -151,9 +207,7 @@ func makeclosure(func_ *Node) *Node { ...@@ -151,9 +207,7 @@ func makeclosure(func_ *Node) *Node {
// create the function // create the function
xfunc = Nod(ODCLFUNC, nil, nil) xfunc = Nod(ODCLFUNC, nil, nil)
makeclosure_closgen++ xfunc.Nname = newname(closurename(func_))
namebuf = fmt.Sprintf("func·%.3d", makeclosure_closgen)
xfunc.Nname = newname(Lookup(namebuf))
xfunc.Nname.Sym.Flags |= SymExported // disable export xfunc.Nname.Sym.Flags |= SymExported // disable export
xfunc.Nname.Ntype = xtype xfunc.Nname.Ntype = xtype
xfunc.Nname.Defn = xfunc xfunc.Nname.Defn = xfunc
...@@ -412,7 +466,7 @@ func walkclosure(func_ *Node, init **NodeList) *Node { ...@@ -412,7 +466,7 @@ func walkclosure(func_ *Node, init **NodeList) *Node {
// and has one float64 argument and no results, // and has one float64 argument and no results,
// the generated code looks like: // the generated code looks like:
// //
// clos = &struct{F uintptr; A0 *int; A1 *string}{func·001, &i, &s} // clos = &struct{.F uintptr; i *int; s *string}{func.1, &i, &s}
// //
// The use of the struct provides type information to the garbage // The use of the struct provides type information to the garbage
// collector so that it can walk the closure. We could use (in this case) // collector so that it can walk the closure. We could use (in this case)
...@@ -423,7 +477,7 @@ func walkclosure(func_ *Node, init **NodeList) *Node { ...@@ -423,7 +477,7 @@ func walkclosure(func_ *Node, init **NodeList) *Node {
typ = Nod(OTSTRUCT, nil, nil) typ = Nod(OTSTRUCT, nil, nil)
typ.List = list1(Nod(ODCLFIELD, newname(Lookup("F")), typenod(Types[TUINTPTR]))) typ.List = list1(Nod(ODCLFIELD, newname(Lookup(".F")), typenod(Types[TUINTPTR])))
for l = func_.Cvars; l != nil; l = l.Next { for l = func_.Cvars; l != nil; l = l.Next {
v = l.N v = l.N
if v.Op == OXXX { if v.Op == OXXX {
...@@ -508,13 +562,11 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node { ...@@ -508,13 +562,11 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
var i int var i int
var ddd int var ddd int
// TODO: names are not right
rcvrtype = fn.Left.Type rcvrtype = fn.Left.Type
if exportname(meth.Sym.Name) { if exportname(meth.Sym.Name) {
p = fmt.Sprintf("%v.%s·fm", Tconv(rcvrtype, obj.FmtLeft|obj.FmtShort), meth.Sym.Name) p = fmt.Sprintf("(%v).%s-fm", Tconv(rcvrtype, obj.FmtLeft|obj.FmtShort), meth.Sym.Name)
} else { } else {
p = fmt.Sprintf("%v.(%v)·fm", Tconv(rcvrtype, obj.FmtLeft|obj.FmtShort), Sconv(meth.Sym, obj.FmtLeft)) p = fmt.Sprintf("(%v).(%v)-fm", Tconv(rcvrtype, obj.FmtLeft|obj.FmtShort), Sconv(meth.Sym, obj.FmtLeft))
} }
basetype = rcvrtype basetype = rcvrtype
if Isptr[rcvrtype.Etype] != 0 { if Isptr[rcvrtype.Etype] != 0 {
......
...@@ -1177,8 +1177,8 @@ var opprec = []int{ ...@@ -1177,8 +1177,8 @@ var opprec = []int{
OSEND: 3, OSEND: 3,
OANDAND: 2, OANDAND: 2,
OOROR: 1, OOROR: 1,
OAS:// Statements handled by stmtfmt // Statements handled by stmtfmt
-1, OAS: -1,
OAS2: -1, OAS2: -1,
OAS2DOTTYPE: -1, OAS2DOTTYPE: -1,
OAS2FUNC: -1, OAS2FUNC: -1,
......
...@@ -203,6 +203,8 @@ type Node struct { ...@@ -203,6 +203,8 @@ type Node struct {
Dcl *NodeList Dcl *NodeList
Inl *NodeList Inl *NodeList
Inldcl *NodeList Inldcl *NodeList
Closgen int
Outerfunc *Node
Val Val Val Val
Ntype *Node Ntype *Node
Defn *Node Defn *Node
......
...@@ -24,14 +24,14 @@ import "fmt" ...@@ -24,14 +24,14 @@ import "fmt"
* it is called by the initialization before * it is called by the initialization before
* main is run. to make it unique within a * main is run. to make it unique within a
* package and also uncallable, the name, * package and also uncallable, the name,
* normally "pkg.init", is altered to "pkg.init·1". * normally "pkg.init", is altered to "pkg.init.1".
*/ */
var renameinit_initgen int var renameinit_initgen int
func renameinit() *Sym { func renameinit() *Sym {
renameinit_initgen++ renameinit_initgen++
namebuf = fmt.Sprintf("init·%d", renameinit_initgen) namebuf = fmt.Sprintf("init.%d", renameinit_initgen)
return Lookup(namebuf) return Lookup(namebuf)
} }
...@@ -48,7 +48,7 @@ func renameinit() *Sym { ...@@ -48,7 +48,7 @@ func renameinit() *Sym {
* // over all matching imported symbols * // over all matching imported symbols
* <pkg>.init() (7) * <pkg>.init() (7)
* { <init stmts> } (8) * { <init stmts> } (8)
* init·<n>() // if any (9) * init.<n>() // if any (9)
* initdone· = 2; (10) * initdone· = 2; (10)
* return (11) * return (11)
* } * }
...@@ -85,9 +85,8 @@ func anyinit(n *NodeList) bool { ...@@ -85,9 +85,8 @@ func anyinit(n *NodeList) bool {
} }
// is there an explicit init function // is there an explicit init function
namebuf = fmt.Sprintf("init·1") s = Lookup("init.1")
s = Lookup(namebuf)
if s.Def != nil { if s.Def != nil {
return true return true
} }
...@@ -201,7 +200,7 @@ func fninit(n *NodeList) { ...@@ -201,7 +200,7 @@ func fninit(n *NodeList) {
// (9) // (9)
// could check that it is fn of no args/returns // could check that it is fn of no args/returns
for i = 1; ; i++ { for i = 1; ; i++ {
namebuf = fmt.Sprintf("init·%d", i) namebuf = fmt.Sprintf("init.%d", i)
s = Lookup(namebuf) s = Lookup(namebuf)
if s.Def == nil { if s.Def == nil {
break break
......
...@@ -409,7 +409,7 @@ func compile(fn *Node) { ...@@ -409,7 +409,7 @@ func compile(fn *Node) {
dowidth(Curfn.Type) dowidth(Curfn.Type)
if fn.Nbody == nil { if fn.Nbody == nil {
if pure_go != 0 || strings.HasPrefix(fn.Nname.Sym.Name, "init·") { if pure_go != 0 || strings.HasPrefix(fn.Nname.Sym.Name, "init.") {
Yyerror("missing function body", fn) Yyerror("missing function body", fn)
goto ret goto ret
} }
......
...@@ -188,7 +188,7 @@ func mapbucket(t *Type) *Type { ...@@ -188,7 +188,7 @@ func mapbucket(t *Type) *Type {
} }
// See comment on hmap.overflow in ../../runtime/hashmap.go. // See comment on hmap.overflow in ../../runtime/hashmap.go.
if !haspointers(t.Type) && !haspointers(t.Down) { if !haspointers(t.Type) && !haspointers(t.Down) && t.Type.Width <= MAXKEYSIZE && t.Down.Width <= MAXVALSIZE {
bucket.Haspointers = 1 // no pointers bucket.Haspointers = 1 // no pointers
} }
......
...@@ -550,6 +550,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) { ...@@ -550,6 +550,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
if false { if false {
// Debug bad returns // Debug bad returns
q = ctxt.NewProg() q = ctxt.NewProg()
q.As = AMOVD q.As = AMOVD
q.Lineno = p.Lineno q.Lineno = p.Lineno
q.From.Type = obj.TYPE_MEM q.From.Type = obj.TYPE_MEM
......
...@@ -719,9 +719,9 @@ func samaddr(f *gc.Node, t *gc.Node) bool { ...@@ -719,9 +719,9 @@ func samaddr(f *gc.Node, t *gc.Node) bool {
func gins(as int, f *gc.Node, t *gc.Node) *obj.Prog { func gins(as int, f *gc.Node, t *gc.Node) *obj.Prog {
var w int32 var w int32
var p *obj.Prog var p *obj.Prog
var af obj.Addr
// Node nod; // Node nod;
var af obj.Addr
var at obj.Addr var at obj.Addr
// if(f != N && f->op == OINDEX) { // if(f != N && f->op == OINDEX) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment