cue: allow getting Runtime from Instance

Needed for goc Codec and probably useful
across the board.

Change-Id: Ib3e2c0b514a09815375f77d3d05d33e0411d20c2
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2710
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/build.go b/cue/build.go
index 4285d63..b00fd86 100644
--- a/cue/build.go
+++ b/cue/build.go
@@ -27,6 +27,7 @@
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/format"
 	"cuelang.org/go/cue/token"
+	"cuelang.org/go/internal"
 )
 
 // A Runtime is used for creating CUE interpretations.
@@ -38,6 +39,12 @@
 	idx *index
 }
 
+func init() {
+	internal.GetRuntime = func(instance interface{}) interface{} {
+		return &Runtime{idx: instance.(*Instance).index}
+	}
+}
+
 func dummyLoad(token.Pos, string) *build.Instance { return nil }
 
 func (r *Runtime) index() *index {
diff --git a/internal/internal.go b/internal/internal.go
index 261b9d6..d9b82a7 100644
--- a/internal/internal.go
+++ b/internal/internal.go
@@ -53,3 +53,6 @@
 
 // UnifyBuiltin returns the given Value unified with the given builtin template.
 var UnifyBuiltin func(v interface{}, kind string) interface{}
+
+// GetRuntime reports the runtime for an Instance.
+var GetRuntime func(instance interface{}) interface{}