...

Source file src/cuelang.org/go/internal/core/eval/eval.go

Documentation: cuelang.org/go/internal/core/eval

     1  // Copyright 2021 CUE Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package eval
    16  
    17  import (
    18  	"cuelang.org/go/cue/stats"
    19  	"cuelang.org/go/internal/core/adt"
    20  	"cuelang.org/go/internal/core/debug"
    21  )
    22  
    23  func Evaluate(r adt.Runtime, v *adt.Vertex) {
    24  	format := func(n adt.Node) string {
    25  		return debug.NodeString(r, n, printConfig)
    26  	}
    27  	c := adt.New(v, &adt.Config{
    28  		Runtime: r,
    29  		Format:  format,
    30  	})
    31  	v.Finalize(c)
    32  }
    33  
    34  func New(r adt.Runtime) *Unifier {
    35  	return &Unifier{r: r, e: NewContext(r, nil)}
    36  }
    37  
    38  type Unifier struct {
    39  	r adt.Runtime
    40  	e *adt.OpContext
    41  }
    42  
    43  func (e *Unifier) Stats() *stats.Counts {
    44  	return e.e.Stats()
    45  }
    46  
    47  // TODO: Note: NewContext takes essentially a cue.Value. By making this
    48  // type more central, we can perhaps avoid context creation.
    49  func NewContext(r adt.Runtime, v *adt.Vertex) *adt.OpContext {
    50  	format := func(n adt.Node) string {
    51  		return debug.NodeString(r, n, printConfig)
    52  	}
    53  	return adt.New(v, &adt.Config{
    54  		Runtime: r,
    55  		Format:  format,
    56  	})
    57  }
    58  
    59  func (e *Unifier) NewContext(v *adt.Vertex) *adt.OpContext {
    60  	return NewContext(e.r, v)
    61  }
    62  
    63  var printConfig = &debug.Config{Compact: true}
    64  

View as plain text