internal: add MakeInstance

And remove EvalExpr, which is now public.

MakeInstance will be used in the cli tool to
convert expressions evaluated within an
instance back to an instance.

Change-Id: If644e7975316b1c3d41d3c645236d3314fc05773
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5201
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/instance.go b/cue/instance.go
index 92b72fe..ae0cd3c 100644
--- a/cue/instance.go
+++ b/cue/instance.go
@@ -69,6 +69,21 @@
 	return imp
 }
 
+func init() {
+	internal.MakeInstance = func(value interface{}) interface{} {
+		v := value.(Value)
+		x := v.eval(v.ctx())
+		st, ok := x.(*structLit)
+		if !ok {
+			st = &structLit{baseValue: x.base(), emit: x}
+		}
+		return v.ctx().index.addInst(&Instance{
+			rootStruct: st,
+			rootValue:  v.path.v,
+		})
+	}
+}
+
 // newInstance creates a new instance. Use Insert to populate the instance.
 func (x *index) newInstance(p *build.Instance) *Instance {
 	// TODO: associate root source with structLit.
diff --git a/internal/internal.go b/internal/internal.go
index 17af682..8c9b33c 100644
--- a/internal/internal.go
+++ b/internal/internal.go
@@ -70,9 +70,12 @@
 // 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.
+// GetRuntime reports the runtime for an Instance or Value.
 var GetRuntime func(instance interface{}) interface{}
 
+// MakeInstance makes a new instance from a value.
+var MakeInstance func(value interface{}) (instance interface{})
+
 // CheckAndForkRuntime checks that value is created using runtime, panicking
 // if it does not, and returns a forked runtime that will discard additional
 // keys.