Skip to content

Commit

Permalink
Only generate init when there are startup lines (#865)
Browse files Browse the repository at this point in the history
Fixes #864
  • Loading branch information
kroppt committed Jul 20, 2020
1 parent 0307ff6 commit 99646ac
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions transpiler/transpiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ func TranspileAST(fileName, packageName string, p *program.Program, root ast.Nod
})
}

// Now we need to build the __init() function. This sets up certain state
// and variables that the runtime expects to be ready.
p.File.Decls = append(p.File.Decls, &goast.FuncDecl{
Name: goast.NewIdent("init"),
Type: util.NewFuncType(&goast.FieldList{}, "", false),
Body: &goast.BlockStmt{
List: p.StartupStatements(),
},
})
if list := p.StartupStatements(); len(list) > 0 {
// Now we need to build the init() function. This sets up certain state
// and variables that the runtime expects to be ready.
p.File.Decls = append(p.File.Decls, &goast.FuncDecl{
Name: goast.NewIdent("init"),
Type: util.NewFuncType(&goast.FieldList{}, "", false),
Body: &goast.BlockStmt{
List: list,
},
})
}

// only for "stdbool.h"
if p.IncludeHeaderIsExists("stdbool.h") {
Expand Down

0 comments on commit 99646ac

Please sign in to comment.