Refactor writeFuncImpl.
@@ -558,8 +558,41 @@ func (g *gen) writeFuncImpl(n *a.Func) error {
"self->private_impl.status = puffs_%s_error_constructor_not_called; return; }\n", g.pkgName)
}
- // For public functions, check the other args for bounds and null-ness.
+ // For public functions, check (at runtime) the other args for bounds and
+ // null-ness. For private functions, those checks are done at compile time.
if n.Public() {
+ if err := g.writeFuncImplArgChecks(n); err != nil {
+ return err
+ }
+ }
+ g.writes("\n")
+
+ // Generate the local variables.
+ if err := g.writeVars(n.Body(), 0); err != nil {
+ return err
+ }
+ g.writes("\n")
+
+ // Generate the function body.
+ for _, o := range n.Body() {
+ if err := g.writeStatement(o, 0); err != nil {
+ return err
+ }
+ }
+ g.writes("\n")
+
+ if g.perFunc.suspendible {
+ if g.perFunc.public {
+ g.printf("cleanup0: self->private_impl.status = status;\n")
+ }
+ g.printf("return status;\n")
+ }
+
+ g.writes("}\n\n")
+ return nil
+}
+
+func (g *gen) writeFuncImplArgChecks(n *a.Func) error {
badArg := false
for _, o := range n.In().Fields() {
o := o.Field()
@@ -623,31 +656,6 @@ func (g *gen) writeFuncImpl(n *a.Func) error {
}
g.writes("}\n")
}
- }
- g.writes("\n")
-
- // Generate the local variables.
- if err := g.writeVars(n.Body(), 0); err != nil {
- return err
- }
- g.writes("\n")
-
- // Generate the function body.
- for _, o := range n.Body() {
- if err := g.writeStatement(o, 0); err != nil {
- return err
- }
- }
- g.writes("\n")
-
- if g.perFunc.suspendible {
- if g.perFunc.public {
- g.printf("cleanup0: self->private_impl.status = status;\n")
- }
- g.printf("return status;\n")
- }
-
- g.writes("}\n\n")
return nil
}
