~mna/snow unlisted

e75e506c6c7d9d02ba86533342870e3d5137d3e8 — Martin Angers 9 months ago 5d44110
pkg/codegen: start codegen for interfaces
M pkg/codegen/mangle.go => pkg/codegen/mangle.go +10 -0
@@ 89,6 89,10 @@ func mangle(unit *semantic.Unit) *nameResolver {
			case *semantic.Struct:
				b.withPrefixFor(decl)
				names[decl] = b.get(decl.Ident())

			case *semantic.Interface:
				b.withPrefixFor(decl)
				names[decl] = b.get(decl.Ident())
			}
		}
		return true


@@ 208,6 212,12 @@ func (b *fmtBuilder) withPrefixFor(decl semantic.Decl) {
		if !decl.Scope().IsTopLevel() {
			b.withScope(decl.Scope())
		}

	case *semantic.Interface:
		b.withExport(false)
		if !decl.Scope().IsTopLevel() {
			b.withScope(decl.Scope())
		}
	}
}


A pkg/codegen/testdata/fn_assign_call_interface.snow => pkg/codegen/testdata/fn_assign_call_interface.snow +21 -0
@@ 0,0 1,21 @@
interface I {
  fn foo()
}

struct S {
  let s: string

  fn foo() {
    println(s)
  }
}

@extern(import: "fmt", symbol: "Println")
fn println(s: string)

fn main() {
  let iface: I = S(s: "hello!")
  iface.foo()
}

#=hello!

M pkg/codegen/translate.go => pkg/codegen/translate.go +10 -0
@@ 169,6 169,16 @@ func (t *translator) Visit(n semantic.Node) semantic.Visitor {
			Specs: []goast.Spec{vs},
		})

	case *semantic.Interface:
		if n.IsGeneric() {
			// go nodes will be generated only on instantiation, create an empty container for now
			m := &mark{list: t.topLevel, elem: t.topLevel.PushBack(newContainer(n))}
			t.genDeclMarks[n] = m
			break
		}
		name := t.resolver.NameForDecl(n)
		t.createInterface(name, semantic.AsInterfaceType(n.Type()))

		// ************** STATEMENTS *****************

	case *semantic.Block: