Skip to content

Commit

Permalink
Merge #158
Browse files Browse the repository at this point in the history
158: compiler: add init function support r=zegl a=zegl



Co-authored-by: Gustav Westling <[email protected]>
  • Loading branch information
bors[bot] and zegl authored Jan 12, 2020
2 parents 40793bf + 8c6bc9c commit a6973f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/compiler/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func (c *Compiler) compileDefineFuncNode(v *parser.DefineFuncNode) value.Value {
funcRetType = types.I32
fn = c.mainFunc
entry = fn.Blocks[0] // use already defined block
} else if v.Name == "init" {
fn = c.module.NewFunc(name.Var("init"), funcRetType.LLVM(), llvmParams...)
entry = fn.NewBlock(name.Block())
c.initGlobalsFunc.Blocks[0].NewCall(fn) // Setup call to init from the global init func
} else {
fn = c.module.NewFunc(compiledName, funcRetType.LLVM(), llvmParams...)
entry = fn.NewBlock(name.Block())
Expand Down
13 changes: 13 additions & 0 deletions compiler/testdata/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

func init() {
print("1\n") // 1
}

func init() {
print("2\n") // 2
}

func main() {
print("3\n") // 3
}

0 comments on commit a6973f7

Please sign in to comment.