github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/environment/runtime.go (about)

     1  package environment
     2  
     3  import (
     4  	cadenceRuntime "github.com/onflow/cadence/runtime"
     5  
     6  	"github.com/onflow/flow-go/fvm/runtime"
     7  )
     8  
     9  type RuntimeParams struct {
    10  	runtime.ReusableCadenceRuntimePool
    11  }
    12  
    13  func DefaultRuntimeParams() RuntimeParams {
    14  	return RuntimeParams{
    15  		ReusableCadenceRuntimePool: runtime.NewReusableCadenceRuntimePool(
    16  			0,
    17  			cadenceRuntime.Config{},
    18  		),
    19  	}
    20  }
    21  
    22  // Runtime expose the cadence runtime to the rest of the envionment package.
    23  type Runtime struct {
    24  	RuntimeParams
    25  
    26  	env Environment
    27  }
    28  
    29  func NewRuntime(params RuntimeParams) *Runtime {
    30  	return &Runtime{
    31  		RuntimeParams: params,
    32  	}
    33  }
    34  
    35  func (runtime *Runtime) SetEnvironment(env Environment) {
    36  	runtime.env = env
    37  }
    38  
    39  func (runtime *Runtime) BorrowCadenceRuntime() *runtime.ReusableCadenceRuntime {
    40  	return runtime.ReusableCadenceRuntimePool.Borrow(runtime.env)
    41  }
    42  
    43  func (runtime *Runtime) ReturnCadenceRuntime(
    44  	reusable *runtime.ReusableCadenceRuntime,
    45  ) {
    46  	runtime.ReusableCadenceRuntimePool.Return(reusable)
    47  }