提交 cb393db0 编写于 作者: B Ben Shi

llvm: implement support of internal anonymous functions.

上级 42a5c407
......@@ -15,6 +15,7 @@ wa native global_constant.wa
wa native global_variable_0.wa
wa native global_variable_1.wa
wa native heart.wa
wa native internal_function.wa
wa native loop_0.wa
wa native loop_1.wa
wa native multi_ret.wa
......
# Test the llvm backend.
# Test anonymous functions and closure functions.
fn main() {
print("Hello, ")
fn() {
println("World!")
}()
var i: int
show := fn() {
println("i = ", i)
}
for i = 0; i < 10; i++ {
show()
}
}
......@@ -21,6 +21,7 @@ type Compiler struct {
output strings.Builder
debug bool
fmts []FmtStr
anofn []*ssa.Function
}
func New(target string, debug bool) *Compiler {
......@@ -142,6 +143,14 @@ func (p *Compiler) compilePackage(pkg *ssa.Package) error {
}
}
// Generate LLVM-IR for each internal function.
for _, v := range p.anofn {
if err := p.compileFunction(v); err != nil {
return err
}
}
p.anofn = []*ssa.Function{}
return nil
}
......
......@@ -387,6 +387,10 @@ func (p *Compiler) compileCall(val *ssa.Call) error {
// Emit the function name.
p.output.WriteString(" @")
callee := val.Call.StaticCallee()
// This callee is an internal function, whose body will be genereated later.
if callee.Parent() != nil {
p.anofn = append(p.anofn, callee)
}
if len(callee.LinkName()) > 0 {
p.output.WriteString(callee.LinkName())
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册