...

Source file src/cuelang.org/go/internal/core/adt/dev.go

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

     1  // Copyright 2023 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 adt
    16  
    17  // This file contains types to help in the transition from the old to new
    18  // evaluation model.
    19  
    20  func unreachableForDev(c *OpContext) {
    21  	if c.isDevVersion() {
    22  		panic("unreachable for development version")
    23  	}
    24  }
    25  
    26  type combinedFlags uint32
    27  
    28  // oldOnly indicates that a Vertex should only be evaluated for the old
    29  // evaluator.
    30  func oldOnly(state vertexStatus) combinedFlags {
    31  	return combinedFlags(state) |
    32  		combinedFlags(ignore)<<8 |
    33  		combinedFlags(allKnown)<<16
    34  }
    35  
    36  func combineMode(cond condition, mode runMode) combinedFlags {
    37  	return combinedFlags(mode)<<8 | combinedFlags(cond)<<16
    38  }
    39  
    40  func attempt(state vertexStatus, cond condition) combinedFlags {
    41  	return combinedFlags(state) | combineMode(cond, attemptOnly)
    42  }
    43  
    44  func require(state vertexStatus, cond condition) combinedFlags {
    45  	return combinedFlags(state) | combineMode(cond, yield)
    46  }
    47  
    48  func final(state vertexStatus, cond condition) combinedFlags {
    49  	return combinedFlags(state) | combineMode(cond, finalize)
    50  }
    51  
    52  func deprecated(c *OpContext, state vertexStatus) combinedFlags {
    53  	// if c.isDevVersion() {
    54  	// 	panic("calling function may not be used in new evaluator")
    55  	// }
    56  	return combinedFlags(state)
    57  }
    58  
    59  func (f combinedFlags) vertexStatus() vertexStatus {
    60  	return vertexStatus(f & 0xff)
    61  }
    62  
    63  func (f combinedFlags) withVertexStatus(x vertexStatus) combinedFlags {
    64  	f &^= 0xff
    65  	f |= combinedFlags(x)
    66  	return f
    67  }
    68  
    69  func (f combinedFlags) conditions() condition {
    70  	return condition(f >> 16)
    71  }
    72  
    73  func (f combinedFlags) runMode() runMode {
    74  	return runMode(f>>8) & 0xff
    75  }
    76  
    77  func (f combinedFlags) ignore() bool {
    78  	return f&(combinedFlags(ignore)<<8) != 0
    79  }
    80  

View as plain text