compiler: Implement interface calls

This is a big combined change. Other changes in this commit:

  * Analyze makeinterface and make sure type switches don't include
    unnecessary cases.
  * Do not include CGo wrapper functions in the analyzer callgraph.
    This also avoids some unnecessary type IDs.
  * Give all Go named structs a name in LLVM.
  * Use such a named struct for compiler-generated task data.
  * Use the type and function names defined by the ssa and types
    package instead of generating our own.
  * Some improvements to function pointers.
  * A few other minor improvements.

The one thing lacking here is interface-to-interface assertions.
This commit is contained in:
Ayke van Laethem
2018-06-10 00:36:39 +02:00
parent 62325eab40
commit a97ca91c1f
5 changed files with 478 additions and 119 deletions
+19 -6
View File
@@ -9,6 +9,10 @@ func (t Thing) String() string {
return t.name
}
type Stringer interface {
String() string
}
const SIX = 6
func main() {
@@ -20,21 +24,26 @@ func main() {
println("sumrange(100) =", sumrange(100))
println("strlen foo:", strlen("foo"))
thing := Thing{"foo"}
thing := &Thing{"foo"}
println("thing:", thing.String())
printItf(5)
printItf(byte('x'))
printItf("foo")
printItf(*thing)
printItf(thing)
printItf(Stringer(thing))
s := Stringer(thing)
println("Stringer.String():", s.String())
runFunc(hello) // must be indirect to avoid obvious inlining
runFunc(hello, 5) // must be indirect to avoid obvious inlining
}
func runFunc(f func()) {
f()
func runFunc(f func(int), arg int) {
f(arg)
}
func hello() {
println("hello from function pointer!")
func hello(n int) {
println("hello from function pointer:", n)
}
func strlen(s string) int {
@@ -49,6 +58,10 @@ func printItf(val interface{}) {
println("is byte:", val)
case string:
println("is string:", val)
case Thing:
println("is Thing:", val.String())
case *Thing:
println("is *Thing:", val.String())
default:
println("is ?")
}