cgen: fix interface struct sorting

pull/4647/head
joe-conigliaro 2020-04-29 21:08:39 +10:00
parent 51d0ce0222
commit 98cd013908
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
2 changed files with 11 additions and 7 deletions

View File

@ -599,11 +599,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
} }
ast.Import {} ast.Import {}
ast.InterfaceDecl { ast.InterfaceDecl {
g.definitions.writeln('//interface') // definitions are sorted and added in write_types
g.definitions.writeln('typedef struct {')
g.definitions.writeln('\tvoid* _object;')
g.definitions.writeln('\tint _interface_idx;')
g.definitions.writeln('} $it.name;')
} }
ast.Module { ast.Module {
g.is_builtin_mod = it.name == 'builtin' g.is_builtin_mod = it.name == 'builtin'
@ -2271,6 +2267,13 @@ int typ;
g.definitions.writeln('typedef $fixed $styp [$len];') g.definitions.writeln('typedef $fixed $styp [$len];')
// } // }
} }
table.Interface {
g.definitions.writeln('//interface')
g.definitions.writeln('typedef struct {')
g.definitions.writeln('\tvoid* _object;')
g.definitions.writeln('\tint _interface_idx;')
g.definitions.writeln('} $typ.name;')
}
else {} else {}
} }
} }
@ -2287,6 +2290,7 @@ fn (g Gen) sort_structs(typesa []table.TypeSymbol) []table.TypeSymbol {
// loop over types // loop over types
for t in typesa { for t in typesa {
if t.kind == .interface_ { if t.kind == .interface_ {
dep_graph.add(t.name, [])
continue continue
} }
// create list of deps // create list of deps

View File

@ -81,7 +81,7 @@ interface Speaker2 {
struct Foo { struct Foo {
//speaker Speaker speaker Speaker
//speakers []Speaker speakers []Speaker
} }