go/ssa/interp: add two intrinsics to fix tests

(specifically: strings.Count, testing.callerEntry)

The interpreter tests were very useful for finding bugs during
development of go/ssa but now seem to be all cost and no benefit.
It may be time to delete this package.

Change-Id: I22348be9fb37bb0fd0c572c3e6f57e70fc069e02
Reviewed-on: https://go-review.googlesource.com/40871
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/go/ssa/interp/external.go b/go/ssa/interp/external.go
index 65fe4ba..84c1dd8 100644
--- a/go/ssa/interp/external.go
+++ b/go/ssa/interp/external.go
@@ -113,6 +113,7 @@
 		"runtime.environ":                  ext۰runtime۰environ,
 		"runtime.getgoroot":                ext۰runtime۰getgoroot,
 		"strings.init":                     ext۰nop, // avoid asm dependency
+		"strings.Count":                    ext۰strings۰Count,
 		"strings.Index":                    ext۰strings۰Index,
 		"strings.IndexByte":                ext۰strings۰IndexByte,
 		"sync.runtime_Semacquire":          ext۰nop, // unimplementable
@@ -136,6 +137,7 @@
 		"sync/atomic.LoadUint64":           ext۰atomic۰LoadUint64,
 		"sync/atomic.StoreInt64":           ext۰atomic۰StoreInt64,
 		"sync/atomic.StoreUint64":          ext۰atomic۰StoreUint64,
+		"testing.callerEntry":              ext۰testing۰callerEntry,
 		"testing.runExample":               ext۰testing۰runExample,
 		"time.Sleep":                       ext۰time۰Sleep,
 		"time.now":                         ext۰time۰now,
@@ -279,7 +281,7 @@
 		}
 	}
 	i := 0
-	for fr != nil {
+	for fr != nil && i < len(pc) {
 		pc[i] = uintptr(unsafe.Pointer(fr.fn))
 		i++
 		fr = fr.caller
@@ -308,6 +310,11 @@
 	return os.Getenv("GOROOT")
 }
 
+func ext۰strings۰Count(fr *frame, args []value) value {
+	// Call compiled version to avoid asm dependency.
+	return strings.Count(args[0].(string), args[1].(string))
+}
+
 func ext۰strings۰IndexByte(fr *frame, args []value) value {
 	// Call compiled version to avoid asm dependency.
 	return strings.IndexByte(args[0].(string), args[1].(byte))
@@ -515,6 +522,10 @@
 	return true
 }
 
+func ext۰testing۰callerEntry(fr *frame, args []value) value {
+	return uintptr(0) // bogus implementation for now
+}
+
 func ext۰time۰now(fr *frame, args []value) value {
 	nano := time.Now().UnixNano()
 	return tuple{int64(nano / 1e9), int32(nano % 1e9), int64(0)}