n.Func = new(Func)
n.Func.FCurfn = Curfn
dclcontext = PPARAM
- markdcl()
- Funcdepth++
- n.Func.Outer = Curfn
- Curfn = n
+
+ funcstart(n)
funcargs(n.Right)
// funcbody is normally called after the parser has
}
dclcontext = PAUTO
- markdcl()
- Funcdepth++
-
- n.Func.Outer = Curfn
- Curfn = n
+ funcstart(n)
if n.Func.Nname != nil {
funcargs(n.Func.Nname.Name.Param.Ntype)
}
}
+var funcstack []*Node // stack of previous values of Curfn
+var Funcdepth int32 // len(funcstack) during parsing, but then forced to be the same later during compilation
+
+
+// start the function.
+// called before funcargs; undone at end of funcbody.
+func funcstart(n *Node) {
+ markdcl()
+ funcstack = append(funcstack, Curfn)
+ Funcdepth++
+ Curfn = n
+}
+
// finish the body.
// called in auto-declaration context.
// returns in extern-declaration context.
Fatalf("funcbody: unexpected dclcontext %d", dclcontext)
}
popdcl()
+ funcstack, Curfn = funcstack[:len(funcstack)-1], funcstack[len(funcstack)-1]
Funcdepth--
- Curfn = n.Func.Outer
- n.Func.Outer = nil
if Funcdepth == 0 {
dclcontext = PEXTERN
}
Dcl []*Node // autodcl for this func/closure
Inldcl Nodes // copy of dcl for use in inlining
Closgen int
- Outerfunc *Node
+ Outerfunc *Node // outer function (for closure)
FieldTrack map[*Sym]struct{}
- Outer *Node // outer func for closure
Ntype *Node // signature
Top int // top context (Ecall, Eproc, etc)
Closure *Node // OCLOSURE <-> ODCLFUNC