Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal: add MakeInstance
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mpvl committed Mar 6, 2020
1 parent d9e4b53 commit c1b5e62
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions cue/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ func (x *index) getImportFromNode(v value) *Instance {
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.
Expand Down
5 changes: 4 additions & 1 deletion internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ var DropOptional bool
// 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.
Expand Down

0 comments on commit c1b5e62

Please sign in to comment.