Skip to content

Commit

Permalink
Merge pull request #2746 from onflow/janez/make-code-and-programs-pub…
Browse files Browse the repository at this point in the history
…lic-2
  • Loading branch information
janezpodhostnik authored Aug 30, 2023
2 parents c5ea847 + d4b8e93 commit 5254952
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions runtime/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ type Context struct {
CoverageReport *CoverageReport
}

// codesAndPrograms collects the source code and AST for each location.
// CodesAndPrograms collects the source code and AST for each location.
// It is purely used for debugging: Both the codes and the programs
// are provided in runtime errors.
type codesAndPrograms struct {
type CodesAndPrograms struct {
codes map[Location][]byte
programs map[Location]*ast.Program
}

func (c codesAndPrograms) setCode(location Location, code []byte) {
func (c CodesAndPrograms) setCode(location Location, code []byte) {
c.codes[location] = code
}

func (c codesAndPrograms) setProgram(location Location, program *ast.Program) {
func (c CodesAndPrograms) setProgram(location Location, program *ast.Program) {
c.programs[location] = program
}

func newCodesAndPrograms() codesAndPrograms {
return codesAndPrograms{
func NewCodesAndPrograms() CodesAndPrograms {
return CodesAndPrograms{
codes: map[Location][]byte{},
programs: map[Location]*ast.Program{},
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/contract_function_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type interpreterContractFunctionExecutor struct {
result cadence.Value
executeErr error
preprocessErr error
codesAndPrograms codesAndPrograms
codesAndPrograms CodesAndPrograms
runtime *interpreterRuntime
storage *Storage
contractLocation common.AddressLocation
Expand Down Expand Up @@ -90,7 +90,7 @@ func (executor *interpreterContractFunctionExecutor) preprocess() (err error) {
context := executor.context
location := context.Location

codesAndPrograms := newCodesAndPrograms()
codesAndPrograms := NewCodesAndPrograms()
executor.codesAndPrograms = codesAndPrograms

interpreterRuntime := executor.runtime
Expand Down
6 changes: 3 additions & 3 deletions runtime/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Environment interface {
Declare(valueDeclaration stdlib.StandardLibraryValue)
Configure(
runtimeInterface Interface,
codesAndPrograms codesAndPrograms,
codesAndPrograms CodesAndPrograms,
storage *Storage,
coverageReport *CoverageReport,
)
Expand Down Expand Up @@ -73,7 +73,7 @@ type interpreterEnvironmentReconfigured struct {
runtimeInterface Interface
storage *Storage
coverageReport *CoverageReport
codesAndPrograms codesAndPrograms
codesAndPrograms CodesAndPrograms
}

type interpreterEnvironment struct {
Expand Down Expand Up @@ -186,7 +186,7 @@ func NewScriptInterpreterEnvironment(config Config) Environment {

func (e *interpreterEnvironment) Configure(
runtimeInterface Interface,
codesAndPrograms codesAndPrograms,
codesAndPrograms CodesAndPrograms,
storage *Storage,
coverageReport *CoverageReport,
) {
Expand Down
2 changes: 1 addition & 1 deletion runtime/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Error struct {
Programs map[Location]*ast.Program
}

func newError(err error, location Location, codesAndPrograms codesAndPrograms) Error {
func newError(err error, location Location, codesAndPrograms CodesAndPrograms) Error {
return Error{
Err: err,
Location: location,
Expand Down
12 changes: 6 additions & 6 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (r *interpreterRuntime) Config() Config {
return r.defaultConfig
}

func (r *interpreterRuntime) Recover(onError func(Error), location Location, codesAndPrograms codesAndPrograms) {
func (r *interpreterRuntime) Recover(onError func(Error), location Location, codesAndPrograms CodesAndPrograms) {
recovered := recover()
if recovered == nil {
return
Expand All @@ -234,7 +234,7 @@ func (r *interpreterRuntime) Recover(onError func(Error), location Location, cod
onError(err)
}

func getWrappedError(recovered any, location Location, codesAndPrograms codesAndPrograms) Error {
func getWrappedError(recovered any, location Location, codesAndPrograms CodesAndPrograms) Error {
switch recovered := recovered.(type) {

// If the error is already a `runtime.Error`, then avoid redundant wrapping.
Expand Down Expand Up @@ -513,7 +513,7 @@ func (r *interpreterRuntime) ParseAndCheckProgram(
) {
location := context.Location

codesAndPrograms := newCodesAndPrograms()
codesAndPrograms := NewCodesAndPrograms()

defer r.Recover(
func(internalErr Error) {
Expand Down Expand Up @@ -552,7 +552,7 @@ func (r *interpreterRuntime) Storage(context Context) (*Storage, *interpreter.In

location := context.Location

codesAndPrograms := newCodesAndPrograms()
codesAndPrograms := NewCodesAndPrograms()

storage := NewStorage(context.Interface, context.Interface)

Expand Down Expand Up @@ -589,7 +589,7 @@ func (r *interpreterRuntime) ReadStored(
) {
location := context.Location

var codesAndPrograms codesAndPrograms
var codesAndPrograms CodesAndPrograms

defer r.Recover(
func(internalErr Error) {
Expand Down Expand Up @@ -635,7 +635,7 @@ func (r *interpreterRuntime) ReadLinked(
) {
location := context.Location

var codesAndPrograms codesAndPrograms
var codesAndPrograms CodesAndPrograms

defer r.Recover(
func(internalErr Error) {
Expand Down
4 changes: 2 additions & 2 deletions runtime/script_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
type interpreterScriptExecutorPreparation struct {
environment Environment
preprocessErr error
codesAndPrograms codesAndPrograms
codesAndPrograms CodesAndPrograms
functionEntryPointType *sema.FunctionType
program *interpreter.Program
storage *Storage
Expand Down Expand Up @@ -92,7 +92,7 @@ func (executor *interpreterScriptExecutor) preprocess() (err error) {
location := context.Location
script := executor.script

codesAndPrograms := newCodesAndPrograms()
codesAndPrograms := NewCodesAndPrograms()
executor.codesAndPrograms = codesAndPrograms

interpreterRuntime := executor.runtime
Expand Down
4 changes: 2 additions & 2 deletions runtime/transaction_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

type interpreterTransactionExecutorPreparation struct {
codesAndPrograms codesAndPrograms
codesAndPrograms CodesAndPrograms
environment Environment
preprocessErr error
transactionType *sema.TransactionType
Expand Down Expand Up @@ -92,7 +92,7 @@ func (executor *interpreterTransactionExecutor) preprocess() (err error) {
location := context.Location
script := executor.script

codesAndPrograms := newCodesAndPrograms()
codesAndPrograms := NewCodesAndPrograms()
executor.codesAndPrograms = codesAndPrograms

interpreterRuntime := executor.runtime
Expand Down

0 comments on commit 5254952

Please sign in to comment.