From a475233f361c98661595bad0a93f661f0ae3e928 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 18 Aug 2018 01:12:52 +0200 Subject: [PATCH] Support recursive types --- compiler.go | 14 +++++++++++--- ir.go | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/compiler.go b/compiler.go index 9387c79b..f35434f6 100644 --- a/compiler.go +++ b/compiler.go @@ -216,7 +216,16 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error { var frames []*Frame - // Declare all named (struct) types. + // Declare all named struct types. + for _, t := range c.ir.NamedTypes { + if named, ok := t.t.Type().(*types.Named); ok { + if _, ok := named.Underlying().(*types.Struct); ok { + t.llvmType = c.ctx.StructCreateNamed(named.Obj().Pkg().Path() + "." + named.Obj().Name()) + } + } + } + + // Define all named struct types. for _, t := range c.ir.NamedTypes { if named, ok := t.t.Type().(*types.Named); ok { if st, ok := named.Underlying().(*types.Struct); ok { @@ -224,8 +233,7 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error { if err != nil { return err } - llvmNamedType := c.ctx.StructCreateNamed(named.Obj().Pkg().Path() + "." + named.Obj().Name()) - llvmNamedType.StructSetBody(llvmType.StructElementTypes(), false) + t.llvmType.StructSetBody(llvmType.StructElementTypes(), false) } } } diff --git a/ir.go b/ir.go index 76dde3f3..56d28846 100644 --- a/ir.go +++ b/ir.go @@ -41,7 +41,8 @@ type Global struct { // Type with a name and possibly methods. type NamedType struct { - t *ssa.Type + t *ssa.Type + llvmType llvm.Type } // Type that is at some point put in an interface.