Skip to content

Commit 2edb646

Browse files
committed
Decouple 'Invocation' from the 'Interpreter'
1 parent c6ab2b3 commit 2edb646

37 files changed

+277
-266
lines changed

interpreter/conversion.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/onflow/cadence/errors"
2626
)
2727

28-
func ByteArrayValueToByteSlice(interpreter *Interpreter, value Value, locationRange LocationRange) ([]byte, error) {
28+
func ByteArrayValueToByteSlice(context ContainerMutationContext, value Value, locationRange LocationRange) ([]byte, error) {
2929
array, ok := value.(*ArrayValue)
3030
if !ok {
3131
return nil, errors.NewDefaultUserError("value is not an array")
@@ -39,10 +39,10 @@ func ByteArrayValueToByteSlice(interpreter *Interpreter, value Value, locationRa
3939

4040
var err error
4141
array.Iterate(
42-
interpreter,
42+
context,
4343
func(element Value) (resume bool) {
4444
var b byte
45-
b, err = ByteValueToByte(interpreter, element, locationRange)
45+
b, err = ByteValueToByte(context, element, locationRange)
4646
if err != nil {
4747
return false
4848
}

interpreter/interface.go

+10
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ type EventContext interface {
251251

252252
var _ EventContext = &Interpreter{}
253253

254+
// InvocationContext is a composite of all contexts, since function invocations
255+
// can perform various operations, and hence need to provide all possible contexts to it.
256+
type InvocationContext interface {
257+
StorageContext
258+
ValueStringContext
259+
MemberAccessibleContext
260+
}
261+
262+
var _ InvocationContext = &Interpreter{}
263+
254264
// NoOpStringContext is the ValueStringContext implementation used in Value.RecursiveString method.
255265
// Since Value.RecursiveString is a non-mutating operation, it should only need the no-op memory metering
256266
// and a WithMutationPrevention implementation.

interpreter/interface_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) {
11311131
``,
11321132
func(invocation interpreter.Invocation) interpreter.Value {
11331133
message := invocation.Arguments[0].MeteredString(
1134-
invocation.Interpreter,
1134+
invocation.InvocationContext,
11351135
interpreter.SeenReferences{},
11361136
invocation.LocationRange,
11371137
)

0 commit comments

Comments
 (0)