From 5be8fd135104eb252e6c5163cfd6502ddadaa3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Tue, 26 Nov 2024 14:03:00 -0800 Subject: [PATCH 1/8] decouple Value.StaticType from interpreter --- interpreter/interface.go | 55 +++++++++++++++++++ interpreter/simplecompositevalue.go | 2 +- interpreter/value.go | 2 +- .../value_accountcapabilitycontroller.go | 2 +- interpreter/value_address.go | 4 +- interpreter/value_array.go | 6 +- interpreter/value_bool.go | 4 +- interpreter/value_capability.go | 4 +- interpreter/value_character.go | 4 +- interpreter/value_composite.go | 4 +- interpreter/value_dictionary.go | 2 +- interpreter/value_ephemeral_reference.go | 6 +- interpreter/value_fix64.go | 4 +- interpreter/value_function.go | 12 ++-- interpreter/value_int.go | 4 +- interpreter/value_int128.go | 4 +- interpreter/value_int16.go | 4 +- interpreter/value_int256.go | 4 +- interpreter/value_int32.go | 4 +- interpreter/value_int64.go | 4 +- interpreter/value_int8.go | 4 +- interpreter/value_link.go | 10 ++-- interpreter/value_nil.go | 6 +- interpreter/value_path.go | 8 +-- interpreter/value_pathcapability.go | 4 +- interpreter/value_placeholder.go | 2 +- interpreter/value_published.go | 4 +- interpreter/value_some.go | 6 +- interpreter/value_storage_reference.go | 18 +++--- .../value_storagecapabilitycontroller.go | 2 +- interpreter/value_string.go | 4 +- interpreter/value_type.go | 4 +- interpreter/value_ufix64.go | 4 +- interpreter/value_uint.go | 4 +- interpreter/value_uint128.go | 4 +- interpreter/value_uint16.go | 4 +- interpreter/value_uint256.go | 4 +- interpreter/value_uint32.go | 4 +- interpreter/value_uint64.go | 4 +- interpreter/value_uint8.go | 4 +- interpreter/value_void.go | 4 +- interpreter/value_word128.go | 4 +- interpreter/value_word16.go | 4 +- interpreter/value_word256.go | 4 +- interpreter/value_word32.go | 4 +- interpreter/value_word64.go | 4 +- interpreter/value_word8.go | 4 +- 47 files changed, 161 insertions(+), 106 deletions(-) create mode 100644 interpreter/interface.go diff --git a/interpreter/interface.go b/interpreter/interface.go new file mode 100644 index 0000000000..f9fa690572 --- /dev/null +++ b/interpreter/interface.go @@ -0,0 +1,55 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Flow Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package interpreter + +import ( + "github.com/onflow/cadence/common" + "github.com/onflow/cadence/sema" +) + +type TypeConverter interface { + MustConvertStaticToSemaType(staticType StaticType) sema.Type +} + +var _ TypeConverter = &Interpreter{} + +type SubTypeChecker interface { + IsSubTypeOfSemaType(staticSubType StaticType, superType sema.Type) bool +} + +var _ SubTypeChecker = &Interpreter{} + +type StorageReader interface { + ReadStored( + storageAddress common.Address, + domain common.StorageDomain, + identifier StorageMapKey, + ) Value +} + +var _ StorageReader = &Interpreter{} + +type StaticTypeGetter interface { + common.MemoryGauge + StorageReader + TypeConverter + SubTypeChecker +} + +var _ StaticTypeGetter = &Interpreter{} diff --git a/interpreter/simplecompositevalue.go b/interpreter/simplecompositevalue.go index 01620523e7..1a624889e2 100644 --- a/interpreter/simplecompositevalue.go +++ b/interpreter/simplecompositevalue.go @@ -103,7 +103,7 @@ func (v *SimpleCompositeValue) Walk(_ *Interpreter, walkChild func(Value), _ Loc }) } -func (v *SimpleCompositeValue) StaticType(_ *Interpreter) StaticType { +func (v *SimpleCompositeValue) StaticType(_ StaticTypeGetter) StaticType { return v.staticType } diff --git a/interpreter/value.go b/interpreter/value.go index bf698515c5..ff1bf9fc78 100644 --- a/interpreter/value.go +++ b/interpreter/value.go @@ -94,7 +94,7 @@ type Value interface { isValue() Accept(interpreter *Interpreter, visitor Visitor, locationRange LocationRange) Walk(interpreter *Interpreter, walkChild func(Value), locationRange LocationRange) - StaticType(interpreter *Interpreter) StaticType + StaticType(staticTypeGetter StaticTypeGetter) StaticType // ConformsToStaticType returns true if the value (i.e. its dynamic type) // conforms to its own static type. // Non-container values trivially always conform to their own static type. diff --git a/interpreter/value_accountcapabilitycontroller.go b/interpreter/value_accountcapabilitycontroller.go index c2036e271a..541ad1e82f 100644 --- a/interpreter/value_accountcapabilitycontroller.go +++ b/interpreter/value_accountcapabilitycontroller.go @@ -96,7 +96,7 @@ func (v *AccountCapabilityControllerValue) Walk(_ *Interpreter, walkChild func(V walkChild(v.CapabilityID) } -func (v *AccountCapabilityControllerValue) StaticType(_ *Interpreter) StaticType { +func (v *AccountCapabilityControllerValue) StaticType(_ StaticTypeGetter) StaticType { return PrimitiveStaticTypeAccountCapabilityController } diff --git a/interpreter/value_address.go b/interpreter/value_address.go index 56ec54163c..05ab268f03 100644 --- a/interpreter/value_address.go +++ b/interpreter/value_address.go @@ -101,8 +101,8 @@ func (AddressValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (AddressValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeAddress) +func (AddressValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeAddress) } func (AddressValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_array.go b/interpreter/value_array.go index b032b9625c..73a01cdb83 100644 --- a/interpreter/value_array.go +++ b/interpreter/value_array.go @@ -324,7 +324,7 @@ func (v *ArrayValue) Walk( ) } -func (v *ArrayValue) StaticType(_ *Interpreter) StaticType { +func (v *ArrayValue) StaticType(_ StaticTypeGetter) StaticType { // TODO meter return v.Type } @@ -1538,10 +1538,10 @@ func (v *ArrayValue) GetOwner() common.Address { return common.Address(v.StorageAddress()) } -func (v *ArrayValue) SemaType(interpreter *Interpreter) sema.ArrayType { +func (v *ArrayValue) SemaType(typeConverter TypeConverter) sema.ArrayType { if v.semaType == nil { // this function will panic already if this conversion fails - v.semaType, _ = interpreter.MustConvertStaticToSemaType(v.Type).(sema.ArrayType) + v.semaType, _ = typeConverter.MustConvertStaticToSemaType(v.Type).(sema.ArrayType) } return v.semaType } diff --git a/interpreter/value_bool.go b/interpreter/value_bool.go index 31222efcc9..61cc63ea52 100644 --- a/interpreter/value_bool.go +++ b/interpreter/value_bool.go @@ -56,8 +56,8 @@ func (BoolValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (BoolValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeBool) +func (BoolValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeBool) } func (BoolValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_capability.go b/interpreter/value_capability.go index 8d766c6c48..9dd83df4f2 100644 --- a/interpreter/value_capability.go +++ b/interpreter/value_capability.go @@ -108,9 +108,9 @@ func (v *IDCapabilityValue) Walk(_ *Interpreter, walkChild func(Value), _ Locati walkChild(v.address) } -func (v *IDCapabilityValue) StaticType(inter *Interpreter) StaticType { +func (v *IDCapabilityValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { return NewCapabilityStaticType( - inter, + staticTypeGetter, v.BorrowType, ) } diff --git a/interpreter/value_character.go b/interpreter/value_character.go index 66e57da154..f6c6c435cf 100644 --- a/interpreter/value_character.go +++ b/interpreter/value_character.go @@ -86,8 +86,8 @@ func (CharacterValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (CharacterValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeCharacter) +func (CharacterValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeCharacter) } func (CharacterValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_composite.go b/interpreter/value_composite.go index cf460d466d..58e5f87200 100644 --- a/interpreter/value_composite.go +++ b/interpreter/value_composite.go @@ -264,12 +264,12 @@ func (v *CompositeValue) Walk(interpreter *Interpreter, walkChild func(Value), l }, locationRange) } -func (v *CompositeValue) StaticType(interpreter *Interpreter) StaticType { +func (v *CompositeValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { if v.staticType == nil { // NOTE: Instead of using NewCompositeStaticType, which always generates the type ID, // use the TypeID accessor, which may return an already computed type ID v.staticType = NewCompositeStaticType( - interpreter, + staticTypeGetter, v.Location, v.QualifiedIdentifier, v.TypeID(), diff --git a/interpreter/value_dictionary.go b/interpreter/value_dictionary.go index b7b804c465..d7c78aa759 100644 --- a/interpreter/value_dictionary.go +++ b/interpreter/value_dictionary.go @@ -441,7 +441,7 @@ func (v *DictionaryValue) Walk(interpreter *Interpreter, walkChild func(Value), ) } -func (v *DictionaryValue) StaticType(_ *Interpreter) StaticType { +func (v *DictionaryValue) StaticType(_ StaticTypeGetter) StaticType { // TODO meter return v.Type } diff --git a/interpreter/value_ephemeral_reference.go b/interpreter/value_ephemeral_reference.go index 94e505cc1b..13a99fc5ab 100644 --- a/interpreter/value_ephemeral_reference.go +++ b/interpreter/value_ephemeral_reference.go @@ -111,11 +111,11 @@ func (v *EphemeralReferenceValue) MeteredString(interpreter *Interpreter, seenRe return v.Value.MeteredString(interpreter, seenReferences, locationRange) } -func (v *EphemeralReferenceValue) StaticType(inter *Interpreter) StaticType { +func (v *EphemeralReferenceValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { return NewReferenceStaticType( - inter, + staticTypeGetter, v.Authorization, - v.Value.StaticType(inter), + v.Value.StaticType(staticTypeGetter), ) } diff --git a/interpreter/value_fix64.go b/interpreter/value_fix64.go index 8d975bb11c..9f4798915f 100644 --- a/interpreter/value_fix64.go +++ b/interpreter/value_fix64.go @@ -93,8 +93,8 @@ func (Fix64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Fix64Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeFix64) +func (Fix64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeFix64) } func (Fix64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_function.go b/interpreter/value_function.go index f5d8b99f45..9240699bee 100644 --- a/interpreter/value_function.go +++ b/interpreter/value_function.go @@ -103,8 +103,8 @@ func (f *InterpretedFunctionValue) Walk(_ *Interpreter, _ func(Value), _ Locatio // NO-OP } -func (f *InterpretedFunctionValue) StaticType(interpreter *Interpreter) StaticType { - return ConvertSemaToStaticType(interpreter, f.Type) +func (f *InterpretedFunctionValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return ConvertSemaToStaticType(staticTypeGetter, f.Type) } func (*InterpretedFunctionValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -237,8 +237,8 @@ func (f *HostFunctionValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) // NO-OP } -func (f *HostFunctionValue) StaticType(interpreter *Interpreter) StaticType { - return ConvertSemaToStaticType(interpreter, f.Type) +func (f *HostFunctionValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return ConvertSemaToStaticType(staticTypeGetter, f.Type) } func (*HostFunctionValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -413,8 +413,8 @@ func (f BoundFunctionValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) // NO-OP } -func (f BoundFunctionValue) StaticType(inter *Interpreter) StaticType { - return f.Function.StaticType(inter) +func (f BoundFunctionValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return f.Function.StaticType(staticTypeGetter) } func (BoundFunctionValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int.go b/interpreter/value_int.go index a9e6ef2c51..323dd2b6b7 100644 --- a/interpreter/value_int.go +++ b/interpreter/value_int.go @@ -109,8 +109,8 @@ func (IntValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (IntValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt) +func (IntValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt) } func (IntValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int128.go b/interpreter/value_int128.go index b95c3b70f9..b9bfd07a85 100644 --- a/interpreter/value_int128.go +++ b/interpreter/value_int128.go @@ -82,8 +82,8 @@ func (Int128Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int128Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt128) +func (Int128Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt128) } func (Int128Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int16.go b/interpreter/value_int16.go index 393093b153..647703b9a0 100644 --- a/interpreter/value_int16.go +++ b/interpreter/value_int16.go @@ -69,8 +69,8 @@ func (Int16Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int16Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt16) +func (Int16Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt16) } func (Int16Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int256.go b/interpreter/value_int256.go index c766978af7..29d68aa4e6 100644 --- a/interpreter/value_int256.go +++ b/interpreter/value_int256.go @@ -82,8 +82,8 @@ func (Int256Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int256Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt256) +func (Int256Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt256) } func (Int256Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int32.go b/interpreter/value_int32.go index e5847fc477..ecf3d4f44d 100644 --- a/interpreter/value_int32.go +++ b/interpreter/value_int32.go @@ -69,8 +69,8 @@ func (Int32Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int32Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt32) +func (Int32Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt32) } func (Int32Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int64.go b/interpreter/value_int64.go index 5f331e95aa..26a29e9f3e 100644 --- a/interpreter/value_int64.go +++ b/interpreter/value_int64.go @@ -66,8 +66,8 @@ func (Int64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int64Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt64) +func (Int64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt64) } func (Int64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int8.go b/interpreter/value_int8.go index 12cc547687..e628ff8b96 100644 --- a/interpreter/value_int8.go +++ b/interpreter/value_int8.go @@ -67,8 +67,8 @@ func (Int8Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int8Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeInt8) +func (Int8Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt8) } func (Int8Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_link.go b/interpreter/value_link.go index 0d7cd306e6..3b0e90da8a 100644 --- a/interpreter/value_link.go +++ b/interpreter/value_link.go @@ -59,7 +59,7 @@ func (v PathLinkValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { panic(errors.NewUnreachableError()) } -func (v PathLinkValue) StaticType(interpreter *Interpreter) StaticType { +func (v PathLinkValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { // When iterating over public/private paths, // the values at these paths are PathLinkValues, // placed there by the `link` function. @@ -67,7 +67,7 @@ func (v PathLinkValue) StaticType(interpreter *Interpreter) StaticType { // These are loaded as links, however, // for the purposes of checking their type, // we treat them as capabilities - return NewCapabilityStaticType(interpreter, v.Type) + return NewCapabilityStaticType(staticTypeGetter, v.Type) } func (PathLinkValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -184,7 +184,7 @@ func (AccountLinkValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { panic(errors.NewUnreachableError()) } -func (v AccountLinkValue) StaticType(interpreter *Interpreter) StaticType { +func (v AccountLinkValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { // When iterating over public/private paths, // the values at these paths are AccountLinkValues, // placed there by the `linkAccount` function. @@ -193,9 +193,9 @@ func (v AccountLinkValue) StaticType(interpreter *Interpreter) StaticType { // for the purposes of checking their type, // we treat them as capabilities return NewCapabilityStaticType( - interpreter, + staticTypeGetter, NewReferenceStaticType( - interpreter, + staticTypeGetter, FullyEntitledAccountAccess, PrimitiveStaticTypeAccount, ), diff --git a/interpreter/value_nil.go b/interpreter/value_nil.go index 8bd6459658..9bf4e94cc4 100644 --- a/interpreter/value_nil.go +++ b/interpreter/value_nil.go @@ -51,10 +51,10 @@ func (NilValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (NilValue) StaticType(interpreter *Interpreter) StaticType { +func (NilValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { return NewOptionalStaticType( - interpreter, - NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeNever), + staticTypeGetter, + NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeNever), ) } diff --git a/interpreter/value_path.go b/interpreter/value_path.go index 54c6503c8a..f3a67d44ae 100644 --- a/interpreter/value_path.go +++ b/interpreter/value_path.go @@ -65,14 +65,14 @@ func (PathValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (v PathValue) StaticType(interpreter *Interpreter) StaticType { +func (v PathValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { switch v.Domain { case common.PathDomainStorage: - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeStoragePath) + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeStoragePath) case common.PathDomainPublic: - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypePublicPath) + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypePublicPath) case common.PathDomainPrivate: - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypePrivatePath) + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypePrivatePath) default: panic(errors.NewUnreachableError()) } diff --git a/interpreter/value_pathcapability.go b/interpreter/value_pathcapability.go index d12e460f8c..b95aa3ecd7 100644 --- a/interpreter/value_pathcapability.go +++ b/interpreter/value_pathcapability.go @@ -69,9 +69,9 @@ func (v *PathCapabilityValue) Walk(_ *Interpreter, walkChild func(Value), _ Loca walkChild(v.Path) } -func (v *PathCapabilityValue) StaticType(inter *Interpreter) StaticType { +func (v *PathCapabilityValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { return NewCapabilityStaticType( - inter, + staticTypeGetter, v.BorrowType, ) } diff --git a/interpreter/value_placeholder.go b/interpreter/value_placeholder.go index 1396f38458..30a2d8c5f9 100644 --- a/interpreter/value_placeholder.go +++ b/interpreter/value_placeholder.go @@ -51,7 +51,7 @@ func (f placeholderValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (f placeholderValue) StaticType(_ *Interpreter) StaticType { +func (f placeholderValue) StaticType(_ StaticTypeGetter) StaticType { return PrimitiveStaticTypeNever } diff --git a/interpreter/value_published.go b/interpreter/value_published.go index 39821a32c4..c76b62283a 100644 --- a/interpreter/value_published.go +++ b/interpreter/value_published.go @@ -53,10 +53,10 @@ func (v *PublishedValue) Accept(interpreter *Interpreter, visitor Visitor, _ Loc visitor.VisitPublishedValue(interpreter, v) } -func (v *PublishedValue) StaticType(interpreter *Interpreter) StaticType { +func (v *PublishedValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { // checking the static type of a published value should show us the // static type of the underlying value - return v.Value.StaticType(interpreter) + return v.Value.StaticType(staticTypeGetter) } func (*PublishedValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_some.go b/interpreter/value_some.go index f33f524b81..bac5afbc54 100644 --- a/interpreter/value_some.go +++ b/interpreter/value_some.go @@ -66,17 +66,17 @@ func (v *SomeValue) Walk(_ *Interpreter, walkChild func(Value), _ LocationRange) walkChild(v.value) } -func (v *SomeValue) StaticType(inter *Interpreter) StaticType { +func (v *SomeValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { if v.isDestroyed { return nil } - innerType := v.value.StaticType(inter) + innerType := v.value.StaticType(staticTypeGetter) if innerType == nil { return nil } return NewOptionalStaticType( - inter, + staticTypeGetter, innerType, ) } diff --git a/interpreter/value_storage_reference.go b/interpreter/value_storage_reference.go index 906edc5819..19ceb465a0 100644 --- a/interpreter/value_storage_reference.go +++ b/interpreter/value_storage_reference.go @@ -98,8 +98,8 @@ func (v *StorageReferenceValue) MeteredString(interpreter *Interpreter, _ SeenRe return v.String() } -func (v *StorageReferenceValue) StaticType(inter *Interpreter) StaticType { - referencedValue, err := v.dereference(inter, EmptyLocationRange) +func (v *StorageReferenceValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + referencedValue, err := v.dereference(staticTypeGetter, EmptyLocationRange) if err != nil { panic(err) } @@ -107,9 +107,9 @@ func (v *StorageReferenceValue) StaticType(inter *Interpreter) StaticType { self := *referencedValue return NewReferenceStaticType( - inter, + staticTypeGetter, v.Authorization, - self.StaticType(inter), + self.StaticType(staticTypeGetter), ) } @@ -121,14 +121,14 @@ func (*StorageReferenceValue) IsImportable(_ *Interpreter, _ LocationRange) bool return false } -func (v *StorageReferenceValue) dereference(interpreter *Interpreter, locationRange LocationRange) (*Value, error) { +func (v *StorageReferenceValue) dereference(staticTypeGetter StaticTypeGetter, locationRange LocationRange) (*Value, error) { address := v.TargetStorageAddress domain := v.TargetPath.Domain.StorageDomain() identifier := v.TargetPath.Identifier storageMapKey := StringStorageMapKey(identifier) - referenced := interpreter.ReadStored(address, domain, storageMapKey) + referenced := staticTypeGetter.ReadStored(address, domain, storageMapKey) if referenced == nil { return nil, nil } @@ -141,10 +141,10 @@ func (v *StorageReferenceValue) dereference(interpreter *Interpreter, locationRa } if v.BorrowedType != nil { - staticType := referenced.StaticType(interpreter) + staticType := referenced.StaticType(staticTypeGetter) - if !interpreter.IsSubTypeOfSemaType(staticType, v.BorrowedType) { - semaType := interpreter.MustConvertStaticToSemaType(staticType) + if !staticTypeGetter.IsSubTypeOfSemaType(staticType, v.BorrowedType) { + semaType := staticTypeGetter.MustConvertStaticToSemaType(staticType) return nil, ForceCastTypeMismatchError{ ExpectedType: v.BorrowedType, diff --git a/interpreter/value_storagecapabilitycontroller.go b/interpreter/value_storagecapabilitycontroller.go index 55ef98359c..00f13e49e5 100644 --- a/interpreter/value_storagecapabilitycontroller.go +++ b/interpreter/value_storagecapabilitycontroller.go @@ -118,7 +118,7 @@ func (v *StorageCapabilityControllerValue) Walk(_ *Interpreter, walkChild func(V walkChild(v.CapabilityID) } -func (v *StorageCapabilityControllerValue) StaticType(_ *Interpreter) StaticType { +func (v *StorageCapabilityControllerValue) StaticType(_ StaticTypeGetter) StaticType { return PrimitiveStaticTypeStorageCapabilityController } diff --git a/interpreter/value_string.go b/interpreter/value_string.go index df4e4cc3b6..989e74d82c 100644 --- a/interpreter/value_string.go +++ b/interpreter/value_string.go @@ -121,8 +121,8 @@ func (*StringValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (*StringValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeString) +func (*StringValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeString) } func (*StringValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_type.go b/interpreter/value_type.go index ed41180734..513f5644cb 100644 --- a/interpreter/value_type.go +++ b/interpreter/value_type.go @@ -65,8 +65,8 @@ func (TypeValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (TypeValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeMetaType) +func (TypeValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeMetaType) } func (TypeValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_ufix64.go b/interpreter/value_ufix64.go index 53dd967167..ca7d9fd642 100644 --- a/interpreter/value_ufix64.go +++ b/interpreter/value_ufix64.go @@ -86,8 +86,8 @@ func (UFix64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UFix64Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUFix64) +func (UFix64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUFix64) } func (UFix64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint.go b/interpreter/value_uint.go index aec0c661e3..038fe7e172 100644 --- a/interpreter/value_uint.go +++ b/interpreter/value_uint.go @@ -124,8 +124,8 @@ func (UIntValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UIntValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt) +func (UIntValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt) } func (v UIntValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint128.go b/interpreter/value_uint128.go index e0d7cb0e92..8f43fb31d0 100644 --- a/interpreter/value_uint128.go +++ b/interpreter/value_uint128.go @@ -82,8 +82,8 @@ func (UInt128Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt128Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt128) +func (UInt128Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt128) } func (UInt128Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint16.go b/interpreter/value_uint16.go index c12bd1d2a9..39e7281287 100644 --- a/interpreter/value_uint16.go +++ b/interpreter/value_uint16.go @@ -67,8 +67,8 @@ func (UInt16Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt16Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt16) +func (UInt16Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt16) } func (UInt16Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint256.go b/interpreter/value_uint256.go index 975454387a..e660f8aaf0 100644 --- a/interpreter/value_uint256.go +++ b/interpreter/value_uint256.go @@ -82,8 +82,8 @@ func (UInt256Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt256Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt256) +func (UInt256Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt256) } func (UInt256Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint32.go b/interpreter/value_uint32.go index 83c7efb59f..cd486c6573 100644 --- a/interpreter/value_uint32.go +++ b/interpreter/value_uint32.go @@ -67,8 +67,8 @@ func (UInt32Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt32Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt32) +func (UInt32Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt32) } func (UInt32Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint64.go b/interpreter/value_uint64.go index f8b3cdb2ce..dc62a35143 100644 --- a/interpreter/value_uint64.go +++ b/interpreter/value_uint64.go @@ -74,8 +74,8 @@ func (UInt64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt64Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt64) +func (UInt64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt64) } func (UInt64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_uint8.go b/interpreter/value_uint8.go index d2289f2ef1..8dc8670de4 100644 --- a/interpreter/value_uint8.go +++ b/interpreter/value_uint8.go @@ -67,8 +67,8 @@ func (UInt8Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt8Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeUInt8) +func (UInt8Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt8) } func (UInt8Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_void.go b/interpreter/value_void.go index 9ad8e54222..fc452d5adc 100644 --- a/interpreter/value_void.go +++ b/interpreter/value_void.go @@ -47,8 +47,8 @@ func (VoidValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (VoidValue) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeVoid) +func (VoidValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeVoid) } func (VoidValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word128.go b/interpreter/value_word128.go index d845055941..f85eab3e0b 100644 --- a/interpreter/value_word128.go +++ b/interpreter/value_word128.go @@ -82,8 +82,8 @@ func (Word128Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word128Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord128) +func (Word128Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord128) } func (Word128Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word16.go b/interpreter/value_word16.go index 98d50f5264..fa8050ad0b 100644 --- a/interpreter/value_word16.go +++ b/interpreter/value_word16.go @@ -68,8 +68,8 @@ func (Word16Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word16Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord16) +func (Word16Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord16) } func (Word16Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word256.go b/interpreter/value_word256.go index 49924b6240..a36cbb59d6 100644 --- a/interpreter/value_word256.go +++ b/interpreter/value_word256.go @@ -82,8 +82,8 @@ func (Word256Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word256Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord256) +func (Word256Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord256) } func (Word256Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word32.go b/interpreter/value_word32.go index 13d92e5add..425b52adb4 100644 --- a/interpreter/value_word32.go +++ b/interpreter/value_word32.go @@ -68,8 +68,8 @@ func (Word32Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word32Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord32) +func (Word32Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord32) } func (Word32Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word64.go b/interpreter/value_word64.go index b79cec602b..c958e8303f 100644 --- a/interpreter/value_word64.go +++ b/interpreter/value_word64.go @@ -76,8 +76,8 @@ func (Word64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word64Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord64) +func (Word64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord64) } func (Word64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_word8.go b/interpreter/value_word8.go index 8fffdf9c7d..932ff26ca6 100644 --- a/interpreter/value_word8.go +++ b/interpreter/value_word8.go @@ -67,8 +67,8 @@ func (Word8Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word8Value) StaticType(interpreter *Interpreter) StaticType { - return NewPrimitiveStaticType(interpreter, PrimitiveStaticTypeWord8) +func (Word8Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { + return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord8) } func (Word8Value) IsImportable(_ *Interpreter, _ LocationRange) bool { From ba888b5b943da46f7cb48c6e3f58357a9c99d1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 2 Dec 2024 14:49:55 -0800 Subject: [PATCH 2/8] decouple Value.Equal from Interpreter, remove unnecessary parameters --- interpreter/account_test.go | 14 +++--- interpreter/attachments_test.go | 4 +- interpreter/builtinfunctions_test.go | 2 +- interpreter/dynamic_casting_test.go | 23 ++++------ interpreter/enum_test.go | 2 +- interpreter/function_test.go | 10 ++--- interpreter/hashablevalue.go | 10 +++-- interpreter/inspect_test.go | 4 +- interpreter/interface.go | 7 +++ interpreter/interpreter.go | 6 +-- interpreter/interpreter_expression.go | 33 +++----------- interpreter/interpreter_statement.go | 6 +-- interpreter/misc_test.go | 45 +++++++++---------- interpreter/reference_test.go | 12 ++--- interpreter/resources_test.go | 28 ++++++------ interpreter/storage_test.go | 4 +- interpreter/value.go | 10 ++--- .../value_accountcapabilitycontroller.go | 8 +--- interpreter/value_address.go | 6 +-- interpreter/value_array.go | 12 ++--- interpreter/value_bool.go | 4 +- interpreter/value_capability.go | 4 +- interpreter/value_character.go | 4 +- interpreter/value_composite.go | 28 ++++++------ interpreter/value_dictionary.go | 20 ++++----- interpreter/value_ephemeral_reference.go | 2 +- interpreter/value_fix64.go | 4 +- interpreter/value_int.go | 4 +- interpreter/value_int128.go | 4 +- interpreter/value_int16.go | 6 +-- interpreter/value_int256.go | 6 +-- interpreter/value_int32.go | 6 +-- interpreter/value_int64.go | 6 +-- interpreter/value_int8.go | 6 +-- interpreter/value_link.go | 6 +-- interpreter/value_nil.go | 2 +- interpreter/value_path.go | 6 +-- interpreter/value_pathcapability.go | 6 +-- interpreter/value_published.go | 6 +-- interpreter/value_range.go | 6 +-- interpreter/value_some.go | 12 ++--- interpreter/value_storage_reference.go | 4 +- .../value_storagecapabilitycontroller.go | 10 ++--- interpreter/value_string.go | 6 +-- interpreter/value_test.go | 4 +- interpreter/value_type.go | 6 +-- interpreter/value_ufix64.go | 6 +-- interpreter/value_uint.go | 6 +-- interpreter/value_uint128.go | 6 +-- interpreter/value_uint16.go | 6 +-- interpreter/value_uint256.go | 6 +-- interpreter/value_uint32.go | 6 +-- interpreter/value_uint64.go | 6 +-- interpreter/value_uint8.go | 6 +-- interpreter/value_void.go | 2 +- interpreter/value_word128.go | 6 +-- interpreter/value_word16.go | 6 +-- interpreter/value_word256.go | 6 +-- interpreter/value_word32.go | 6 +-- interpreter/value_word64.go | 6 +-- interpreter/value_word8.go | 6 +-- interpreter/values_test.go | 24 +++++----- runtime/convertValues.go | 6 +-- runtime/events.go | 2 +- stdlib/test_emulatorbackend.go | 2 +- 65 files changed, 251 insertions(+), 293 deletions(-) diff --git a/interpreter/account_test.go b/interpreter/account_test.go index 595d0d7352..600c8827af 100644 --- a/interpreter/account_test.go +++ b/interpreter/account_test.go @@ -713,7 +713,7 @@ func TestInterpretAccountStorageLoad(t *testing.T) { require.IsType(t, &interpreter.SomeValue{}, value) - innerValue := value.(*interpreter.SomeValue).InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := value.(*interpreter.SomeValue).InnerValue() assert.IsType(t, &interpreter.CompositeValue{}, innerValue) @@ -790,7 +790,7 @@ func TestInterpretAccountStorageLoad(t *testing.T) { require.IsType(t, &interpreter.SomeValue{}, value) - innerValue := value.(*interpreter.SomeValue).InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := value.(*interpreter.SomeValue).InnerValue() assert.IsType(t, &interpreter.CompositeValue{}, innerValue) @@ -872,7 +872,7 @@ func TestInterpretAccountStorageCopy(t *testing.T) { require.IsType(t, &interpreter.SomeValue{}, value) - innerValue := value.(*interpreter.SomeValue).InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := value.(*interpreter.SomeValue).InnerValue() assert.IsType(t, &interpreter.CompositeValue{}, innerValue) @@ -1005,7 +1005,7 @@ func TestInterpretAccountStorageBorrow(t *testing.T) { require.IsType(t, &interpreter.SomeValue{}, value) - innerValue := value.(*interpreter.SomeValue).InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := value.(*interpreter.SomeValue).InnerValue() assert.IsType(t, &interpreter.StorageReferenceValue{}, innerValue) @@ -1044,7 +1044,7 @@ func TestInterpretAccountStorageBorrow(t *testing.T) { require.IsType(t, &interpreter.SomeValue{}, value) - innerValue = value.(*interpreter.SomeValue).InnerValue(inter, interpreter.EmptyLocationRange) + innerValue = value.(*interpreter.SomeValue).InnerValue() assert.IsType(t, &interpreter.StorageReferenceValue{}, innerValue) @@ -1183,7 +1183,7 @@ func TestInterpretAccountStorageBorrow(t *testing.T) { require.IsType(t, &interpreter.SomeValue{}, value) - innerValue := value.(*interpreter.SomeValue).InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := value.(*interpreter.SomeValue).InnerValue() assert.IsType(t, &interpreter.StorageReferenceValue{}, innerValue) @@ -1222,7 +1222,7 @@ func TestInterpretAccountStorageBorrow(t *testing.T) { require.IsType(t, &interpreter.SomeValue{}, value) - innerValue = value.(*interpreter.SomeValue).InnerValue(inter, interpreter.EmptyLocationRange) + innerValue = value.(*interpreter.SomeValue).InnerValue() assert.IsType(t, &interpreter.StorageReferenceValue{}, innerValue) diff --git a/interpreter/attachments_test.go b/interpreter/attachments_test.go index 384ee9f647..412792509b 100644 --- a/interpreter/attachments_test.go +++ b/interpreter/attachments_test.go @@ -1517,8 +1517,8 @@ func TestInterpretAttachmentDestructor(t *testing.T) { require.Len(t, events, 2) require.Equal(t, "A.ResourceDestroyed", events[0].QualifiedIdentifier) - require.Equal(t, interpreter.NewUnmeteredStringValue("foo"), events[0].GetField(inter, interpreter.EmptyLocationRange, "foo")) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[0].GetField(inter, interpreter.EmptyLocationRange, "bar")) + require.Equal(t, interpreter.NewUnmeteredStringValue("foo"), events[0].GetField(inter, "foo")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[0].GetField(inter, "bar")) require.Equal(t, "R.ResourceDestroyed", events[1].QualifiedIdentifier) }) } diff --git a/interpreter/builtinfunctions_test.go b/interpreter/builtinfunctions_test.go index 93402c80e5..b114c6adf9 100644 --- a/interpreter/builtinfunctions_test.go +++ b/interpreter/builtinfunctions_test.go @@ -262,7 +262,7 @@ func TestInterpretAddressFromString(t *testing.T) { addressOpt, ok := res.(*interpreter.SomeValue) require.True(t, ok) - innerValue := addressOpt.InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := addressOpt.InnerValue() addressVal, ok := innerValue.(interpreter.AddressValue) require.True(t, ok) require.Equal(t, expected, addressVal.ToAddress().HexWithPrefix()) diff --git a/interpreter/dynamic_casting_test.go b/interpreter/dynamic_casting_test.go index 255a7b719e..391f5e4ec2 100644 --- a/interpreter/dynamic_casting_test.go +++ b/interpreter/dynamic_casting_test.go @@ -607,8 +607,7 @@ func TestInterpretDynamicCastingStruct(t *testing.T) { require.IsType(t, &interpreter.CompositeValue{}, - inter.Globals.Get("y").GetValue(inter).(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange), + inter.Globals.Get("y").GetValue(inter).(*interpreter.SomeValue).InnerValue(), ) }) } @@ -758,8 +757,7 @@ func testResourceCastValid(t *testing.T, types, fromType string, targetType stri require.IsType(t, &interpreter.CompositeValue{}, - value.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange), + value.(*interpreter.SomeValue).InnerValue(), ) case ast.OperationForceCast: @@ -907,8 +905,7 @@ func testStructCastValid(t *testing.T, types, fromType string, targetType string require.IsType(t, &interpreter.CompositeValue{}, - value.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange), + value.(*interpreter.SomeValue).InnerValue(), ) case ast.OperationForceCast: @@ -1221,7 +1218,7 @@ func TestInterpretDynamicCastingArray(t *testing.T) { require.IsType(t, zValue, &interpreter.SomeValue{}) zSome := zValue.(*interpreter.SomeValue) - innerValue := zSome.InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := zSome.InnerValue() require.IsType(t, innerValue, &interpreter.ArrayValue{}) innerArray := innerValue.(*interpreter.ArrayValue) @@ -2282,8 +2279,7 @@ func testReferenceCastValid(t *testing.T, types, fromType, targetType string, op require.IsType(t, &interpreter.EphemeralReferenceValue{}, - value.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange), + value.(*interpreter.SomeValue).InnerValue(), ) case ast.OperationForceCast: @@ -4109,8 +4105,7 @@ func TestInterpretDynamicCastingOptionalUnwrapping(t *testing.T) { require.IsType(t, &interpreter.CompositeValue{}, - value.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange), + value.(*interpreter.SomeValue).InnerValue(), ) }) @@ -4165,8 +4160,7 @@ func TestInterpretDynamicCastingOptionalUnwrapping(t *testing.T) { require.IsType(t, &interpreter.CompositeValue{}, - result.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange), + result.(*interpreter.SomeValue).InnerValue(), ) }) @@ -4202,8 +4196,7 @@ func TestInterpretDynamicCastingOptionalUnwrapping(t *testing.T) { require.IsType(t, &interpreter.CompositeValue{}, - result.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange), + result.(*interpreter.SomeValue).InnerValue(), ) }) diff --git a/interpreter/enum_test.go b/interpreter/enum_test.go index fa3e9a0c05..1e0dd91dd7 100644 --- a/interpreter/enum_test.go +++ b/interpreter/enum_test.go @@ -248,7 +248,7 @@ func TestInterpretEnumInContract(t *testing.T) { require.IsType(t, &interpreter.CompositeValue{}, c) contract := c.(*interpreter.CompositeValue) - eValue := contract.GetField(inter, interpreter.EmptyLocationRange, "e") + eValue := contract.GetField(inter, "e") require.NotNil(t, eValue) require.IsType(t, &interpreter.CompositeValue{}, eValue) diff --git a/interpreter/function_test.go b/interpreter/function_test.go index b16b77c642..3144a54213 100644 --- a/interpreter/function_test.go +++ b/interpreter/function_test.go @@ -64,7 +64,7 @@ func TestInterpretResultVariable(t *testing.T) { t, inter, interpreter.UInt8Value(1), - resource.GetField(inter, interpreter.EmptyLocationRange, "id"), + resource.GetField(inter, "id"), ) }) @@ -93,7 +93,7 @@ func TestInterpretResultVariable(t *testing.T) { require.IsType(t, &interpreter.SomeValue{}, result) someValue := result.(*interpreter.SomeValue) - innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := someValue.InnerValue() require.IsType(t, &interpreter.CompositeValue{}, innerValue) resource := innerValue.(*interpreter.CompositeValue) @@ -102,7 +102,7 @@ func TestInterpretResultVariable(t *testing.T) { t, inter, interpreter.UInt8Value(1), - resource.GetField(inter, interpreter.EmptyLocationRange, "id"), + resource.GetField(inter, "id"), ) }) @@ -157,7 +157,7 @@ func TestInterpretResultVariable(t *testing.T) { require.IsType(t, &interpreter.SomeValue{}, result) someValue := result.(*interpreter.SomeValue) - innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := someValue.InnerValue() require.IsType(t, &interpreter.CompositeValue{}, innerValue) resource := innerValue.(*interpreter.CompositeValue) @@ -166,7 +166,7 @@ func TestInterpretResultVariable(t *testing.T) { t, inter, interpreter.UInt8Value(1), - resource.GetField(inter, interpreter.EmptyLocationRange, "id"), + resource.GetField(inter, "id"), ) }) diff --git a/interpreter/hashablevalue.go b/interpreter/hashablevalue.go index 1040a052a0..d14fc26553 100644 --- a/interpreter/hashablevalue.go +++ b/interpreter/hashablevalue.go @@ -20,18 +20,20 @@ package interpreter import ( "github.com/onflow/atree" + + "github.com/onflow/cadence/common" ) // HashableValue is an immutable value that can be hashed type HashableValue interface { Value - HashInput(interpreter *Interpreter, locationRange LocationRange, scratch []byte) []byte + HashInput(memoryGauge common.MemoryGauge, locationRange LocationRange, scratch []byte) []byte } -func newHashInputProvider(interpreter *Interpreter, locationRange LocationRange) atree.HashInputProvider { +func newHashInputProvider(memoryGauge common.MemoryGauge, locationRange LocationRange) atree.HashInputProvider { return func(value atree.Value, scratch []byte) ([]byte, error) { - hashInput := MustConvertStoredValue(interpreter, value).(HashableValue). - HashInput(interpreter, locationRange, scratch) + hashInput := MustConvertStoredValue(memoryGauge, value).(HashableValue). + HashInput(memoryGauge, locationRange, scratch) return hashInput, nil } } diff --git a/interpreter/inspect_test.go b/interpreter/inspect_test.go index e0ea1ff19f..db406ae51a 100644 --- a/interpreter/inspect_test.go +++ b/interpreter/inspect_test.go @@ -73,8 +73,8 @@ func TestInspectValue(t *testing.T) { // Get actually stored values. // The values above were removed when they were inserted into the containers. - optionalValue := compositeValue.GetField(inter, EmptyLocationRange, "value").(*SomeValue) - arrayValue := optionalValue.InnerValue(inter, EmptyLocationRange).(*ArrayValue) + optionalValue := compositeValue.GetField(inter, "value").(*SomeValue) + arrayValue := optionalValue.InnerValue().(*ArrayValue) dictValue := arrayValue.Get(inter, EmptyLocationRange, 0).(*DictionaryValue) dictValueKey := NewUnmeteredStringValue("hello world") diff --git a/interpreter/interface.go b/interpreter/interface.go index f9fa690572..d31593fd66 100644 --- a/interpreter/interface.go +++ b/interpreter/interface.go @@ -53,3 +53,10 @@ type StaticTypeGetter interface { } var _ StaticTypeGetter = &Interpreter{} + +type ComparisonContext interface { + common.MemoryGauge + StaticTypeGetter +} + +var _ ComparisonContext = &Interpreter{} diff --git a/interpreter/interpreter.go b/interpreter/interpreter.go index efaa58ba94..2191054738 100644 --- a/interpreter/interpreter.go +++ b/interpreter/interpreter.go @@ -2326,7 +2326,7 @@ func (interpreter *Interpreter) BoxOptional( switch typedInner := inner.(type) { case *SomeValue: - inner = typedInner.InnerValue(interpreter, locationRange) + inner = typedInner.InnerValue() case NilValue: // NOTE: nested nil will be unboxed! @@ -2348,7 +2348,7 @@ func (interpreter *Interpreter) Unbox(locationRange LocationRange, value Value) return value } - value = some.InnerValue(interpreter, locationRange) + value = some.InnerValue() } } @@ -4793,7 +4793,7 @@ func GetNativeCompositeValueComputedFields(qualifiedIdentifier string) map[strin locationRange LocationRange, v *CompositeValue, ) Value { - publicKeyValue := v.GetField(interpreter, locationRange, sema.PublicKeyTypePublicKeyFieldName) + publicKeyValue := v.GetField(interpreter, sema.PublicKeyTypePublicKeyFieldName) return publicKeyValue.Transfer( interpreter, locationRange, diff --git a/interpreter/interpreter_expression.go b/interpreter/interpreter_expression.go index 5fecffec0e..bd449c6d61 100644 --- a/interpreter/interpreter_expression.go +++ b/interpreter/interpreter_expression.go @@ -257,7 +257,7 @@ func (interpreter *Interpreter) memberExpressionGetterSetter( return typedTarget case *SomeValue: - target = typedTarget.InnerValue(interpreter, locationRange) + target = typedTarget.InnerValue() default: panic(errors.NewUnreachableError()) @@ -641,7 +641,7 @@ func (interpreter *Interpreter) VisitBinaryExpression(expression *ast.BinaryExpr // only evaluate right-hand side if left-hand side is nil if some, ok := leftValue.(*SomeValue); ok { - return some.InnerValue(interpreter, locationRange) + return some.InnerValue() } value := rightValue() @@ -789,7 +789,7 @@ func (interpreter *Interpreter) VisitUnaryExpression(expression *ast.UnaryExpres if someValue, ok := value.(*SomeValue); ok { isOptional = true - value = someValue.InnerValue(interpreter, locationRange) + value = someValue.InnerValue() } referenceValue, ok := value.(ReferenceValue) @@ -1203,13 +1203,7 @@ func (interpreter *Interpreter) visitInvocationExpressionWithImplicitArgument(in return typedResult case *SomeValue: - result = typedResult.InnerValue( - interpreter, - LocationRange{ - Location: interpreter.Location, - HasPosition: invocationExpression.InvokedExpression, - }, - ) + result = typedResult.InnerValue() default: panic(errors.NewUnreachableError()) @@ -1480,12 +1474,7 @@ func (interpreter *Interpreter) createReference( // References to optionals are transformed into optional references, // so move the *SomeValue out to the reference itself - locationRange := LocationRange{ - Location: interpreter.Location, - HasPosition: hasPosition, - } - - innerValue := value.InnerValue(interpreter, locationRange) + innerValue := value.InnerValue() referenceValue := interpreter.createReference(innerType, innerValue, hasPosition) @@ -1508,11 +1497,7 @@ func (interpreter *Interpreter) createReference( case *sema.ReferenceType: // Case (3): target type is non-optional, actual value is optional. if someValue, ok := value.(*SomeValue); ok { - locationRange := LocationRange{ - Location: interpreter.Location, - HasPosition: hasPosition, - } - innerValue := someValue.InnerValue(interpreter, locationRange) + innerValue := someValue.InnerValue() return interpreter.createReference(typ, innerValue, hasPosition) } @@ -1553,11 +1538,7 @@ func (interpreter *Interpreter) VisitForceExpression(expression *ast.ForceExpres switch result := result.(type) { case *SomeValue: - locationRange := LocationRange{ - Location: interpreter.Location, - HasPosition: expression.Expression, - } - return result.InnerValue(interpreter, locationRange) + return result.InnerValue() case NilValue: panic( diff --git a/interpreter/interpreter_statement.go b/interpreter/interpreter_statement.go index da7aaa0d2c..b925ea68b3 100644 --- a/interpreter/interpreter_statement.go +++ b/interpreter/interpreter_statement.go @@ -153,12 +153,8 @@ func (interpreter *Interpreter) visitIfStatementWithVariableDeclaration( value := interpreter.visitVariableDeclaration(declaration, true) if someValue, ok := value.(*SomeValue); ok { - locationRange := LocationRange{ - Location: interpreter.Location, - HasPosition: declaration.Value, - } - innerValue := someValue.InnerValue(interpreter, locationRange) + innerValue := someValue.InnerValue() interpreter.activations.PushNewWithCurrent() defer interpreter.activations.Pop() diff --git a/interpreter/misc_test.go b/interpreter/misc_test.go index 1784bbcde6..369318466d 100644 --- a/interpreter/misc_test.go +++ b/interpreter/misc_test.go @@ -2598,7 +2598,7 @@ func TestInterpretStructureFieldAssignment(t *testing.T) { t, inter, interpreter.NewUnmeteredIntValueFromInt64(1), - test.GetField(inter, interpreter.EmptyLocationRange, "foo"), + test.GetField(inter, "foo"), ) value, err := inter.Invoke("callTest") @@ -2615,7 +2615,7 @@ func TestInterpretStructureFieldAssignment(t *testing.T) { t, inter, interpreter.NewUnmeteredIntValueFromInt64(3), - test.GetField(inter, interpreter.EmptyLocationRange, "foo"), + test.GetField(inter, "foo"), ) } @@ -6720,9 +6720,9 @@ func TestInterpretResourceMoveInArrayAndDestroy(t *testing.T) { require.Len(t, events, 2) require.Equal(t, "Foo.ResourceDestroyed", events[0].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, interpreter.EmptyLocationRange, "bar")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, "bar")) require.Equal(t, "Foo.ResourceDestroyed", events[1].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[1].GetField(inter, interpreter.EmptyLocationRange, "bar")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[1].GetField(inter, "bar")) } func TestInterpretResourceMoveInDictionaryAndDestroy(t *testing.T) { @@ -6762,9 +6762,9 @@ func TestInterpretResourceMoveInDictionaryAndDestroy(t *testing.T) { require.Len(t, events, 2) require.Equal(t, "Foo.ResourceDestroyed", events[0].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, interpreter.EmptyLocationRange, "bar")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, "bar")) require.Equal(t, "Foo.ResourceDestroyed", events[1].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[1].GetField(inter, interpreter.EmptyLocationRange, "bar")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[1].GetField(inter, "bar")) } func TestInterpretClosure(t *testing.T) { @@ -7073,9 +7073,9 @@ func TestInterpretResourceDestroyExpressionNestedResources(t *testing.T) { require.Len(t, events, 2) require.Equal(t, "B.ResourceDestroyed", events[0].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 5), events[0].GetField(inter, interpreter.EmptyLocationRange, "foo")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 5), events[0].GetField(inter, "foo")) require.Equal(t, "A.ResourceDestroyed", events[1].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 5), events[1].GetField(inter, interpreter.EmptyLocationRange, "foo")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 5), events[1].GetField(inter, "foo")) } func TestInterpretResourceDestroyArray(t *testing.T) { @@ -7851,8 +7851,7 @@ func TestInterpretSwapResourceDictionaryElementReturnDictionary(t *testing.T) { assert.IsType(t, &interpreter.CompositeValue{}, - foo.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange), + foo.(*interpreter.SomeValue).InnerValue(), ) } @@ -7882,8 +7881,7 @@ func TestInterpretSwapResourceDictionaryElementRemoveUsingNil(t *testing.T) { assert.IsType(t, &interpreter.CompositeValue{}, - value.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange), + value.(*interpreter.SomeValue).InnerValue(), ) } @@ -8070,8 +8068,7 @@ func TestInterpretVariableDeclarationSecondValue(t *testing.T) { values[0], ) - firstValue := values[0].(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange) + firstValue := values[0].(*interpreter.SomeValue).InnerValue() require.IsType(t, &interpreter.CompositeValue{}, @@ -8084,7 +8081,7 @@ func TestInterpretVariableDeclarationSecondValue(t *testing.T) { t, inter, interpreter.NewUnmeteredIntValueFromInt64(2), - firstResource.GetField(inter, interpreter.EmptyLocationRange, "id"), + firstResource.GetField(inter, "id"), ) require.IsType(t, @@ -8092,8 +8089,7 @@ func TestInterpretVariableDeclarationSecondValue(t *testing.T) { values[1], ) - secondValue := values[1].(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange) + secondValue := values[1].(*interpreter.SomeValue).InnerValue() require.IsType(t, &interpreter.CompositeValue{}, @@ -8106,7 +8102,7 @@ func TestInterpretVariableDeclarationSecondValue(t *testing.T) { t, inter, interpreter.NewUnmeteredIntValueFromInt64(1), - secondResource.GetField(inter, interpreter.EmptyLocationRange, "id"), + secondResource.GetField(inter, "id"), ) } @@ -8254,8 +8250,7 @@ func TestInterpretOptionalChainingFunctionRead(t *testing.T) { assert.IsType(t, interpreter.BoundFunctionValue{}, - inter.Globals.Get("x2").GetValue(inter).(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange), + inter.Globals.Get("x2").GetValue(inter).(*interpreter.SomeValue).InnerValue(), ) } @@ -9618,14 +9613,14 @@ func TestInterpretNestedDestroy(t *testing.T) { require.Len(t, events, 4) require.Equal(t, "B.ResourceDestroyed", events[0].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[0].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[0].GetField(inter, "id")) require.Equal(t, "B.ResourceDestroyed", events[1].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 3), events[1].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 3), events[1].GetField(inter, "id")) require.Equal(t, "B.ResourceDestroyed", events[2].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 4), events[2].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 4), events[2].GetField(inter, "id")) require.Equal(t, "A.ResourceDestroyed", events[3].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[3].GetField(inter, interpreter.EmptyLocationRange, "id")) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 3), events[3].GetField(inter, interpreter.EmptyLocationRange, "bCount")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[3].GetField(inter, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 3), events[3].GetField(inter, "bCount")) AssertValuesEqual( t, diff --git a/interpreter/reference_test.go b/interpreter/reference_test.go index 273f49d74d..8429948639 100644 --- a/interpreter/reference_test.go +++ b/interpreter/reference_test.go @@ -453,8 +453,7 @@ func TestInterpretReferenceExpressionOfOptional(t *testing.T) { value := inter.Globals.Get("ref").GetValue(inter) require.IsType(t, &interpreter.SomeValue{}, value) - innerValue := value.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := value.(*interpreter.SomeValue).InnerValue() require.IsType(t, &interpreter.EphemeralReferenceValue{}, innerValue) }) @@ -472,8 +471,7 @@ func TestInterpretReferenceExpressionOfOptional(t *testing.T) { value := inter.Globals.Get("ref").GetValue(inter) require.IsType(t, &interpreter.SomeValue{}, value) - innerValue := value.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := value.(*interpreter.SomeValue).InnerValue() require.IsType(t, &interpreter.EphemeralReferenceValue{}, innerValue) }) @@ -489,8 +487,7 @@ func TestInterpretReferenceExpressionOfOptional(t *testing.T) { value := inter.Globals.Get("ref").GetValue(inter) require.IsType(t, &interpreter.SomeValue{}, value) - innerValue := value.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := value.(*interpreter.SomeValue).InnerValue() require.IsType(t, &interpreter.EphemeralReferenceValue{}, innerValue) }) @@ -506,8 +503,7 @@ func TestInterpretReferenceExpressionOfOptional(t *testing.T) { value := inter.Globals.Get("ref").GetValue(inter) require.IsType(t, &interpreter.SomeValue{}, value) - innerValue := value.(*interpreter.SomeValue). - InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := value.(*interpreter.SomeValue).InnerValue() require.IsType(t, &interpreter.EphemeralReferenceValue{}, innerValue) }) diff --git a/interpreter/resources_test.go b/interpreter/resources_test.go index 564c745258..324ad1fb30 100644 --- a/interpreter/resources_test.go +++ b/interpreter/resources_test.go @@ -2338,13 +2338,13 @@ func TestInterpretResourceInterfaceDefaultDestroyEvent(t *testing.T) { require.Len(t, events, 4) require.Equal(t, "I.ResourceDestroyed", events[0].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, "id")) require.Equal(t, "A.ResourceDestroyed", events[1].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[1].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[1].GetField(inter, "id")) require.Equal(t, "I.ResourceDestroyed", events[2].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[2].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[2].GetField(inter, "id")) require.Equal(t, "B.ResourceDestroyed", events[3].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[3].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 2), events[3].GetField(inter, "id")) } func TestInterpretResourceInterfaceDefaultDestroyEventMultipleInheritance(t *testing.T) { @@ -2393,11 +2393,11 @@ func TestInterpretResourceInterfaceDefaultDestroyEventMultipleInheritance(t *tes require.Len(t, events, 3) require.Equal(t, "I.ResourceDestroyed", events[0].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, "id")) require.Equal(t, "J.ResourceDestroyed", events[1].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[1].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[1].GetField(inter, "id")) require.Equal(t, "A.ResourceDestroyed", events[2].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[2].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[2].GetField(inter, "id")) } func TestInterpretResourceInterfaceDefaultDestroyEventIndirectInheritance(t *testing.T) { @@ -2446,11 +2446,11 @@ func TestInterpretResourceInterfaceDefaultDestroyEventIndirectInheritance(t *tes require.Len(t, events, 3) require.Equal(t, "J.ResourceDestroyed", events[0].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, "id")) require.Equal(t, "I.ResourceDestroyed", events[1].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[1].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[1].GetField(inter, "id")) require.Equal(t, "A.ResourceDestroyed", events[2].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[2].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[2].GetField(inter, "id")) } func TestInterpretResourceInterfaceDefaultDestroyEventNoCompositeEvent(t *testing.T) { @@ -2496,7 +2496,7 @@ func TestInterpretResourceInterfaceDefaultDestroyEventNoCompositeEvent(t *testin require.Len(t, events, 1) require.Equal(t, "I.ResourceDestroyed", events[0].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, interpreter.EmptyLocationRange, "id")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, "id")) } func TestInterpreterDefaultDestroyEventBaseShadowing(t *testing.T) { @@ -2553,7 +2553,7 @@ func TestInterpreterDefaultDestroyEventBaseShadowing(t *testing.T) { require.Equal(t, "TrollAttachment.ResourceDestroyed", events[0].QualifiedIdentifier) // should be 1, not 123 - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, interpreter.EmptyLocationRange, "x")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, "x")) }) t.Run("base contract name", func(t *testing.T) { @@ -2602,7 +2602,7 @@ func TestInterpreterDefaultDestroyEventBaseShadowing(t *testing.T) { require.Equal(t, "TrollAttachment.ResourceDestroyed", events[0].QualifiedIdentifier) // should be 1, not 123 - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, interpreter.EmptyLocationRange, "x")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, "x")) }) } @@ -2646,7 +2646,7 @@ func TestInterpretDefaultDestroyEventArgumentScoping(t *testing.T) { require.Len(t, events, 1) require.Equal(t, "R.ResourceDestroyed", events[0].QualifiedIdentifier) - require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, interpreter.EmptyLocationRange, "x")) + require.Equal(t, interpreter.NewIntValueFromInt64(nil, 1), events[0].GetField(inter, "x")) } func TestInterpretVariableDeclarationEvaluationOrder(t *testing.T) { diff --git a/interpreter/storage_test.go b/interpreter/storage_test.go index 21e0f298d3..5df27c1749 100644 --- a/interpreter/storage_test.go +++ b/interpreter/storage_test.go @@ -83,7 +83,7 @@ func TestCompositeStorage(t *testing.T) { t, inter, TrueValue, - storedComposite.GetField(inter, EmptyLocationRange, fieldName), + storedComposite.GetField(inter, fieldName), ) } @@ -139,7 +139,7 @@ func TestInclusiveRangeStorage(t *testing.T) { t, inter, NewUnmeteredInt16Value(10), - storedComposite.GetField(inter, EmptyLocationRange, stepFieldName), + storedComposite.GetField(inter, stepFieldName), ) } diff --git a/interpreter/value.go b/interpreter/value.go index ff1bf9fc78..c0e71ca2db 100644 --- a/interpreter/value.go +++ b/interpreter/value.go @@ -165,14 +165,14 @@ type EquatableValue interface { Value // Equal returns true if the given value is equal to this value. // If no location range is available, pass e.g. EmptyLocationRange - Equal(interpreter *Interpreter, locationRange LocationRange, other Value) bool + Equal(context ComparisonContext, locationRange LocationRange, other Value) bool } -func newValueComparator(interpreter *Interpreter, locationRange LocationRange) atree.ValueComparator { +func newValueComparator(context ComparisonContext, locationRange LocationRange) atree.ValueComparator { return func(storage atree.SlabStorage, atreeValue atree.Value, otherStorable atree.Storable) (bool, error) { - value := MustConvertStoredValue(interpreter, atreeValue) - otherValue := StoredValue(interpreter, otherStorable, storage) - return value.(EquatableValue).Equal(interpreter, locationRange, otherValue), nil + value := MustConvertStoredValue(context, atreeValue) + otherValue := StoredValue(context, otherStorable, storage) + return value.(EquatableValue).Equal(context, locationRange, otherValue), nil } } diff --git a/interpreter/value_accountcapabilitycontroller.go b/interpreter/value_accountcapabilitycontroller.go index 541ad1e82f..be88ce88ff 100644 --- a/interpreter/value_accountcapabilitycontroller.go +++ b/interpreter/value_accountcapabilitycontroller.go @@ -136,18 +136,14 @@ func (v *AccountCapabilityControllerValue) ConformsToStaticType( return true } -func (v *AccountCapabilityControllerValue) Equal( - interpreter *Interpreter, - locationRange LocationRange, - other Value, -) bool { +func (v *AccountCapabilityControllerValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { otherController, ok := other.(*AccountCapabilityControllerValue) if !ok { return false } return otherController.BorrowType.Equal(v.BorrowType) && - otherController.CapabilityID.Equal(interpreter, locationRange, v.CapabilityID) + otherController.CapabilityID.Equal(context, locationRange, v.CapabilityID) } func (*AccountCapabilityControllerValue) IsStorable() bool { diff --git a/interpreter/value_address.go b/interpreter/value_address.go index 05ab268f03..f3ac41982b 100644 --- a/interpreter/value_address.go +++ b/interpreter/value_address.go @@ -117,12 +117,12 @@ func (v AddressValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v AddressValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v AddressValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory(interpreter, common.AddressValueStringMemoryUsage) return v.String() } -func (v AddressValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v AddressValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherAddress, ok := other.(AddressValue) if !ok { return false @@ -133,7 +133,7 @@ func (v AddressValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeAddress (1 byte) // - address (8 bytes) -func (v AddressValue) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v AddressValue) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { length := 1 + len(v) var buffer []byte if length <= len(scratch) { diff --git a/interpreter/value_array.go b/interpreter/value_array.go index 73a01cdb83..b420bea33a 100644 --- a/interpreter/value_array.go +++ b/interpreter/value_array.go @@ -495,7 +495,7 @@ func (v *ArrayValue) handleIndexOutOfBoundsError(err error, index int, locationR } } -func (v *ArrayValue) Get(interpreter *Interpreter, locationRange LocationRange, index int) Value { +func (v *ArrayValue) Get(gauge common.MemoryGauge, locationRange LocationRange, index int) Value { // We only need to check the lower bound before converting from `int` (signed) to `uint64` (unsigned). // atree's Array.Get function will check the upper bound and report an atree.IndexOutOfBoundsError @@ -515,7 +515,7 @@ func (v *ArrayValue) Get(interpreter *Interpreter, locationRange LocationRange, panic(errors.NewExternalError(err)) } - return MustConvertStoredValue(interpreter, storedValue) + return MustConvertStoredValue(gauge, storedValue) } func (v *ArrayValue) SetKey(interpreter *Interpreter, locationRange LocationRange, key Value, value Value) { @@ -1252,7 +1252,7 @@ func (v *ArrayValue) ConformsToStaticType( return !elementMismatch } -func (v *ArrayValue) Equal(interpreter *Interpreter, locationRange LocationRange, other Value) bool { +func (v *ArrayValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { otherArray, ok := other.(*ArrayValue) if !ok { return false @@ -1275,11 +1275,11 @@ func (v *ArrayValue) Equal(interpreter *Interpreter, locationRange LocationRange } for i := 0; i < count; i++ { - value := v.Get(interpreter, locationRange, i) - otherValue := otherArray.Get(interpreter, locationRange, i) + value := v.Get(context, locationRange, i) + otherValue := otherArray.Get(context, locationRange, i) equatableValue, ok := value.(EquatableValue) - if !ok || !equatableValue.Equal(interpreter, locationRange, otherValue) { + if !ok || !equatableValue.Equal(context, locationRange, otherValue) { return false } } diff --git a/interpreter/value_bool.go b/interpreter/value_bool.go index 61cc63ea52..ebdd8969fb 100644 --- a/interpreter/value_bool.go +++ b/interpreter/value_bool.go @@ -71,7 +71,7 @@ func (v BoolValue) Negate(_ *Interpreter) BoolValue { return TrueValue } -func (v BoolValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v BoolValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherBool, ok := other.(BoolValue) if !ok { return false @@ -118,7 +118,7 @@ func (v BoolValue) GreaterEqual(_ *Interpreter, other ComparableValue, _ Locatio // HashInput returns a byte slice containing: // - HashInputTypeBool (1 byte) // - 1/0 (1 byte) -func (v BoolValue) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v BoolValue) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeBool) if v { scratch[1] = 1 diff --git a/interpreter/value_capability.go b/interpreter/value_capability.go index 9dd83df4f2..f2f26625c2 100644 --- a/interpreter/value_capability.go +++ b/interpreter/value_capability.go @@ -181,14 +181,14 @@ func (v *IDCapabilityValue) ConformsToStaticType( return true } -func (v *IDCapabilityValue) Equal(interpreter *Interpreter, locationRange LocationRange, other Value) bool { +func (v *IDCapabilityValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { otherCapability, ok := other.(*IDCapabilityValue) if !ok { return false } return otherCapability.ID == v.ID && - otherCapability.address.Equal(interpreter, locationRange, v.address) && + otherCapability.address.Equal(context, locationRange, v.address) && otherCapability.BorrowType.Equal(v.BorrowType) } diff --git a/interpreter/value_character.go b/interpreter/value_character.go index f6c6c435cf..528458cc6a 100644 --- a/interpreter/value_character.go +++ b/interpreter/value_character.go @@ -108,7 +108,7 @@ func (v CharacterValue) MeteredString(interpreter *Interpreter, _ SeenReferences return v.String() } -func (v CharacterValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v CharacterValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherChar, ok := other.(CharacterValue) if !ok { return false @@ -148,7 +148,7 @@ func (v CharacterValue) GreaterEqual(_ *Interpreter, other ComparableValue, _ Lo return v.Str >= otherChar.Str } -func (v CharacterValue) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v CharacterValue) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { s := []byte(v.Str) length := 1 + len(s) var buffer []byte diff --git a/interpreter/value_composite.go b/interpreter/value_composite.go index 58e5f87200..684427469f 100644 --- a/interpreter/value_composite.go +++ b/interpreter/value_composite.go @@ -457,7 +457,7 @@ func (v *CompositeValue) GetMember(interpreter *Interpreter, locationRange Locat } } - if field := v.GetField(interpreter, locationRange, name); field != nil { + if field := v.GetField(interpreter, name); field != nil { return compositeMember(interpreter, v, field) } @@ -858,7 +858,7 @@ func formatComposite( return format.Composite(typeId, preparedFields) } -func (v *CompositeValue) GetField(interpreter *Interpreter, locationRange LocationRange, name string) Value { +func (v *CompositeValue) GetField(memoryGauge common.MemoryGauge, name string) Value { storedValue, err := v.dictionary.Get( StringAtreeValueComparator, StringAtreeValueHashInput, @@ -872,16 +872,16 @@ func (v *CompositeValue) GetField(interpreter *Interpreter, locationRange Locati panic(errors.NewExternalError(err)) } - return MustConvertStoredValue(interpreter, storedValue) + return MustConvertStoredValue(memoryGauge, storedValue) } -func (v *CompositeValue) Equal(interpreter *Interpreter, locationRange LocationRange, other Value) bool { +func (v *CompositeValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { otherComposite, ok := other.(*CompositeValue) if !ok { return false } - if !v.StaticType(interpreter).Equal(otherComposite.StaticType(interpreter)) || + if !v.StaticType(context).Equal(otherComposite.StaticType(context)) || v.Kind != otherComposite.Kind || v.dictionary.Count() != otherComposite.dictionary.Count() { @@ -906,10 +906,10 @@ func (v *CompositeValue) Equal(interpreter *Interpreter, locationRange LocationR // NOTE: Do NOT use an iterator, iteration order of fields may be different // (if stored in different account, as storage ID is used as hash seed) - otherValue := otherComposite.GetField(interpreter, locationRange, fieldName) + otherValue := otherComposite.GetField(context, fieldName) - equatableValue, ok := MustConvertStoredValue(interpreter, value).(EquatableValue) - if !ok || !equatableValue.Equal(interpreter, locationRange, otherValue) { + equatableValue, ok := MustConvertStoredValue(context, value).(EquatableValue) + if !ok || !equatableValue.Equal(context, locationRange, otherValue) { return false } } @@ -919,13 +919,13 @@ func (v *CompositeValue) Equal(interpreter *Interpreter, locationRange LocationR // - HashInputTypeEnum (1 byte) // - type id (n bytes) // - hash input of raw value field name (n bytes) -func (v *CompositeValue) HashInput(interpreter *Interpreter, locationRange LocationRange, scratch []byte) []byte { +func (v *CompositeValue) HashInput(memoryGauge common.MemoryGauge, locationRange LocationRange, scratch []byte) []byte { if v.Kind == common.CompositeKindEnum { typeID := v.TypeID() - rawValue := v.GetField(interpreter, locationRange, sema.EnumRawValueFieldName) + rawValue := v.GetField(memoryGauge, sema.EnumRawValueFieldName) rawValueHashInput := rawValue.(HashableValue). - HashInput(interpreter, locationRange, scratch) + HashInput(memoryGauge, locationRange, scratch) length := 1 + len(typeID) + len(rawValueHashInput) if length <= len(scratch) { @@ -1031,7 +1031,7 @@ func (v *CompositeValue) CompositeStaticTypeConformsToStaticType( } for _, fieldName := range compositeType.Fields { - value := v.GetField(interpreter, locationRange, fieldName) + value := v.GetField(interpreter, fieldName) if value == nil { if computedFields == nil { return false @@ -1081,7 +1081,7 @@ func (v *CompositeValue) InclusiveRangeStaticTypeConformsToStaticType( expectedMemberStaticType := ConvertSemaToStaticType(interpreter, inclusiveRangeType.MemberType) for _, fieldName := range sema.InclusiveRangeTypeFieldNames { - value := v.GetField(interpreter, locationRange, fieldName) + value := v.GetField(interpreter, fieldName) fieldStaticType := value.StaticType(interpreter) @@ -1351,7 +1351,7 @@ func (v *CompositeValue) Transfer( } func (v *CompositeValue) ResourceUUID(interpreter *Interpreter, locationRange LocationRange) *UInt64Value { - fieldValue := v.GetField(interpreter, locationRange, sema.ResourceUUIDFieldName) + fieldValue := v.GetField(interpreter, sema.ResourceUUIDFieldName) uuid, ok := fieldValue.(UInt64Value) if !ok { return nil diff --git a/interpreter/value_dictionary.go b/interpreter/value_dictionary.go index d7c78aa759..44abd25a25 100644 --- a/interpreter/value_dictionary.go +++ b/interpreter/value_dictionary.go @@ -593,13 +593,13 @@ func (v *DictionaryValue) ContainsKey( } func (v *DictionaryValue) Get( - interpreter *Interpreter, + context ComparisonContext, locationRange LocationRange, keyValue Value, ) (Value, bool) { - valueComparator := newValueComparator(interpreter, locationRange) - hashInputProvider := newHashInputProvider(interpreter, locationRange) + valueComparator := newValueComparator(context, locationRange) + hashInputProvider := newHashInputProvider(context, locationRange) storedValue, err := v.dictionary.Get( valueComparator, @@ -614,7 +614,7 @@ func (v *DictionaryValue) Get( panic(errors.NewExternalError(err)) } - return MustConvertStoredValue(interpreter, storedValue), true + return MustConvertStoredValue(context, storedValue), true } func (v *DictionaryValue) GetKey(interpreter *Interpreter, locationRange LocationRange, keyValue Value) Value { @@ -646,7 +646,7 @@ func (v *DictionaryValue) SetKey( var existingValue Value switch value := value.(type) { case *SomeValue: - innerValue := value.InnerValue(interpreter, locationRange) + innerValue := value.InnerValue() existingValue = v.Insert(interpreter, locationRange, keyValue, innerValue) case NilValue: @@ -1214,7 +1214,7 @@ func (v *DictionaryValue) ConformsToStaticType( } } -func (v *DictionaryValue) Equal(interpreter *Interpreter, locationRange LocationRange, other Value) bool { +func (v *DictionaryValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { otherDictionary, ok := other.(*DictionaryValue) if !ok { @@ -1247,17 +1247,17 @@ func (v *DictionaryValue) Equal(interpreter *Interpreter, locationRange Location // leading to a different iteration order, as the storage ID is used in the seed otherValue, otherValueExists := otherDictionary.Get( - interpreter, + context, locationRange, - MustConvertStoredValue(interpreter, key), + MustConvertStoredValue(context, key), ) if !otherValueExists { return false } - equatableValue, ok := MustConvertStoredValue(interpreter, value).(EquatableValue) - if !ok || !equatableValue.Equal(interpreter, locationRange, otherValue) { + equatableValue, ok := MustConvertStoredValue(context, value).(EquatableValue) + if !ok || !equatableValue.Equal(context, locationRange, otherValue) { return false } } diff --git a/interpreter/value_ephemeral_reference.go b/interpreter/value_ephemeral_reference.go index 13a99fc5ab..0e062074d9 100644 --- a/interpreter/value_ephemeral_reference.go +++ b/interpreter/value_ephemeral_reference.go @@ -241,7 +241,7 @@ func (v *EphemeralReferenceValue) RemoveTypeKey( RemoveTypeKey(interpreter, locationRange, key) } -func (v *EphemeralReferenceValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v *EphemeralReferenceValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherReference, ok := other.(*EphemeralReferenceValue) if !ok || v.Value != otherReference.Value || diff --git a/interpreter/value_fix64.go b/interpreter/value_fix64.go index 9f4798915f..827f538b6f 100644 --- a/interpreter/value_fix64.go +++ b/interpreter/value_fix64.go @@ -456,7 +456,7 @@ func (v Fix64Value) GreaterEqual(interpreter *Interpreter, other ComparableValue return AsBoolValue(v >= o) } -func (v Fix64Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Fix64Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherFix64, ok := other.(Fix64Value) if !ok { return false @@ -467,7 +467,7 @@ func (v Fix64Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeFix64 (1 byte) // - int64 value encoded in big-endian (8 bytes) -func (v Fix64Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Fix64Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeFix64) binary.BigEndian.PutUint64(scratch[1:], uint64(v)) return scratch[:9] diff --git a/interpreter/value_int.go b/interpreter/value_int.go index 323dd2b6b7..1643f2062c 100644 --- a/interpreter/value_int.go +++ b/interpreter/value_int.go @@ -423,7 +423,7 @@ func (v IntValue) GreaterEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(cmp >= 0) } -func (v IntValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v IntValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(IntValue) if !ok { return false @@ -435,7 +435,7 @@ func (v IntValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeInt (1 byte) // - big int encoded in big-endian (n bytes) -func (v IntValue) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v IntValue) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { b := SignedBigIntToBigEndianBytes(v.BigInt) length := 1 + len(b) diff --git a/interpreter/value_int128.go b/interpreter/value_int128.go index b9bfd07a85..529c5a2bf7 100644 --- a/interpreter/value_int128.go +++ b/interpreter/value_int128.go @@ -521,7 +521,7 @@ func (v Int128Value) GreaterEqual(interpreter *Interpreter, other ComparableValu return AsBoolValue(cmp >= 0) } -func (v Int128Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Int128Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(Int128Value) if !ok { return false @@ -533,7 +533,7 @@ func (v Int128Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeInt128 (1 byte) // - big int value encoded in big-endian (n bytes) -func (v Int128Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Int128Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { b := SignedBigIntToBigEndianBytes(v.BigInt) length := 1 + len(b) diff --git a/interpreter/value_int16.go b/interpreter/value_int16.go index 647703b9a0..9851d73ada 100644 --- a/interpreter/value_int16.go +++ b/interpreter/value_int16.go @@ -85,7 +85,7 @@ func (v Int16Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Int16Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Int16Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -455,7 +455,7 @@ func (v Int16Value) GreaterEqual(interpreter *Interpreter, other ComparableValue return AsBoolValue(v >= o) } -func (v Int16Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Int16Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt16, ok := other.(Int16Value) if !ok { return false @@ -466,7 +466,7 @@ func (v Int16Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeInt16 (1 byte) // - int16 value encoded in big-endian (2 bytes) -func (v Int16Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Int16Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeInt16) binary.BigEndian.PutUint16(scratch[1:], uint16(v)) return scratch[:3] diff --git a/interpreter/value_int256.go b/interpreter/value_int256.go index 29d68aa4e6..fcd76b6018 100644 --- a/interpreter/value_int256.go +++ b/interpreter/value_int256.go @@ -116,7 +116,7 @@ func (v Int256Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Int256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Int256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -519,7 +519,7 @@ func (v Int256Value) GreaterEqual(interpreter *Interpreter, other ComparableValu return AsBoolValue(cmp >= 0) } -func (v Int256Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Int256Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(Int256Value) if !ok { return false @@ -531,7 +531,7 @@ func (v Int256Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeInt256 (1 byte) // - big int value encoded in big-endian (n bytes) -func (v Int256Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Int256Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { b := SignedBigIntToBigEndianBytes(v.BigInt) length := 1 + len(b) diff --git a/interpreter/value_int32.go b/interpreter/value_int32.go index ecf3d4f44d..194866fc1c 100644 --- a/interpreter/value_int32.go +++ b/interpreter/value_int32.go @@ -85,7 +85,7 @@ func (v Int32Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Int32Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Int32Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -456,7 +456,7 @@ func (v Int32Value) GreaterEqual(interpreter *Interpreter, other ComparableValue return AsBoolValue(v >= o) } -func (v Int32Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Int32Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt32, ok := other.(Int32Value) if !ok { return false @@ -467,7 +467,7 @@ func (v Int32Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeInt32 (1 byte) // - int32 value encoded in big-endian (4 bytes) -func (v Int32Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Int32Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeInt32) binary.BigEndian.PutUint32(scratch[1:], uint32(v)) return scratch[:5] diff --git a/interpreter/value_int64.go b/interpreter/value_int64.go index 26a29e9f3e..a4f216c6aa 100644 --- a/interpreter/value_int64.go +++ b/interpreter/value_int64.go @@ -82,7 +82,7 @@ func (v Int64Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Int64Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Int64Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -456,7 +456,7 @@ func (v Int64Value) GreaterEqual(interpreter *Interpreter, other ComparableValue return AsBoolValue(v >= o) } -func (v Int64Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Int64Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt64, ok := other.(Int64Value) if !ok { return false @@ -467,7 +467,7 @@ func (v Int64Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeInt64 (1 byte) // - int64 value encoded in big-endian (8 bytes) -func (v Int64Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Int64Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeInt64) binary.BigEndian.PutUint64(scratch[1:], uint64(v)) return scratch[:9] diff --git a/interpreter/value_int8.go b/interpreter/value_int8.go index e628ff8b96..b3aff29499 100644 --- a/interpreter/value_int8.go +++ b/interpreter/value_int8.go @@ -83,7 +83,7 @@ func (v Int8Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Int8Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Int8Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -454,7 +454,7 @@ func (v Int8Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(v >= o) } -func (v Int8Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Int8Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt8, ok := other.(Int8Value) if !ok { return false @@ -465,7 +465,7 @@ func (v Int8Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeInt8 (1 byte) // - int8 value (1 byte) -func (v Int8Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Int8Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeInt8) scratch[1] = byte(v) return scratch[:2] diff --git a/interpreter/value_link.go b/interpreter/value_link.go index 3b0e90da8a..5bebacb76d 100644 --- a/interpreter/value_link.go +++ b/interpreter/value_link.go @@ -98,13 +98,13 @@ func (v PathLinkValue) ConformsToStaticType( panic(errors.NewUnreachableError()) } -func (v PathLinkValue) Equal(interpreter *Interpreter, locationRange LocationRange, other Value) bool { +func (v PathLinkValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { otherLink, ok := other.(PathLinkValue) if !ok { return false } - return otherLink.TargetPath.Equal(interpreter, locationRange, v.TargetPath) && + return otherLink.TargetPath.Equal(context, locationRange, v.TargetPath) && otherLink.Type.Equal(v.Type) } @@ -226,7 +226,7 @@ func (v AccountLinkValue) ConformsToStaticType( panic(errors.NewUnreachableError()) } -func (v AccountLinkValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v AccountLinkValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { _, ok := other.(AccountLinkValue) return ok } diff --git a/interpreter/value_nil.go b/interpreter/value_nil.go index 9bf4e94cc4..a94006aaa2 100644 --- a/interpreter/value_nil.go +++ b/interpreter/value_nil.go @@ -125,7 +125,7 @@ func (v NilValue) ConformsToStaticType( return true } -func (v NilValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v NilValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { _, ok := other.(NilValue) return ok } diff --git a/interpreter/value_path.go b/interpreter/value_path.go index f3a67d44ae..a2673994e7 100644 --- a/interpreter/value_path.go +++ b/interpreter/value_path.go @@ -102,7 +102,7 @@ func (v PathValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v PathValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v PathValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { // len(domain) + len(identifier) + '/' x2 strLen := len(v.Domain.Identifier()) + len(v.Identifier) + 2 common.UseMemory(interpreter, common.NewRawStringMemoryUsage(strLen)) @@ -157,7 +157,7 @@ func (v PathValue) ConformsToStaticType( return true } -func (v PathValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v PathValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherPath, ok := other.(PathValue) if !ok { return false @@ -171,7 +171,7 @@ func (v PathValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // - HashInputTypePath (1 byte) // - domain (1 byte) // - identifier (n bytes) -func (v PathValue) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v PathValue) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { length := 1 + 1 + len(v.Identifier) var buffer []byte if length <= len(scratch) { diff --git a/interpreter/value_pathcapability.go b/interpreter/value_pathcapability.go index b95aa3ecd7..f39572d01f 100644 --- a/interpreter/value_pathcapability.go +++ b/interpreter/value_pathcapability.go @@ -199,7 +199,7 @@ func (v *PathCapabilityValue) ConformsToStaticType( return true } -func (v *PathCapabilityValue) Equal(interpreter *Interpreter, locationRange LocationRange, other Value) bool { +func (v *PathCapabilityValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { otherCapability, ok := other.(*PathCapabilityValue) if !ok { return false @@ -215,8 +215,8 @@ func (v *PathCapabilityValue) Equal(interpreter *Interpreter, locationRange Loca return false } - return otherCapability.address.Equal(interpreter, locationRange, v.address) && - otherCapability.Path.Equal(interpreter, locationRange, v.Path) + return otherCapability.address.Equal(context, locationRange, v.address) && + otherCapability.Path.Equal(context, locationRange, v.Path) } func (*PathCapabilityValue) IsStorable() bool { diff --git a/interpreter/value_published.go b/interpreter/value_published.go index c76b62283a..a9e66a5d12 100644 --- a/interpreter/value_published.go +++ b/interpreter/value_published.go @@ -98,14 +98,14 @@ func (v *PublishedValue) ConformsToStaticType( return false } -func (v *PublishedValue) Equal(interpreter *Interpreter, locationRange LocationRange, other Value) bool { +func (v *PublishedValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { otherValue, ok := other.(*PublishedValue) if !ok { return false } - return otherValue.Recipient.Equal(interpreter, locationRange, v.Recipient) && - otherValue.Value.Equal(interpreter, locationRange, v.Value) + return otherValue.Recipient.Equal(context, locationRange, v.Recipient) && + otherValue.Value.Equal(context, locationRange, v.Value) } func (*PublishedValue) IsStorable() bool { diff --git a/interpreter/value_range.go b/interpreter/value_range.go index baf96bd31f..fb6d780a76 100644 --- a/interpreter/value_range.go +++ b/interpreter/value_range.go @@ -231,11 +231,7 @@ func getFieldAsIntegerValue( name string, ) IntegerValue { return convertAndAssertIntegerValue( - rangeValue.GetField( - interpreter, - locationRange, - name, - ), + rangeValue.GetField(interpreter, name), ) } diff --git a/interpreter/value_some.go b/interpreter/value_some.go index bac5afbc54..854a9785e0 100644 --- a/interpreter/value_some.go +++ b/interpreter/value_some.go @@ -101,7 +101,7 @@ func (v *SomeValue) IsDestroyed() bool { } func (v *SomeValue) Destroy(interpreter *Interpreter, locationRange LocationRange) { - innerValue := v.InnerValue(interpreter, locationRange) + innerValue := v.InnerValue() maybeDestroy(interpreter, locationRange, innerValue) v.isDestroyed = true @@ -185,7 +185,7 @@ func (v *SomeValue) ConformsToStaticType( // SomeValue.StaticType builds type from inner value (if available), // so no need to check it - innerValue := v.InnerValue(interpreter, locationRange) + innerValue := v.InnerValue() return innerValue.ConformsToStaticType( interpreter, @@ -194,20 +194,20 @@ func (v *SomeValue) ConformsToStaticType( ) } -func (v *SomeValue) Equal(interpreter *Interpreter, locationRange LocationRange, other Value) bool { +func (v *SomeValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { otherSome, ok := other.(*SomeValue) if !ok { return false } - innerValue := v.InnerValue(interpreter, locationRange) + innerValue := v.InnerValue() equatableValue, ok := innerValue.(EquatableValue) if !ok { return false } - return equatableValue.Equal(interpreter, locationRange, otherSome.value) + return equatableValue.Equal(context, locationRange, otherSome.value) } func (v *SomeValue) Storable( @@ -365,7 +365,7 @@ func (v *SomeValue) DeepRemove(interpreter *Interpreter, hasNoParentContainer bo } } -func (v *SomeValue) InnerValue(_ *Interpreter, _ LocationRange) Value { +func (v *SomeValue) InnerValue() Value { return v.value } diff --git a/interpreter/value_storage_reference.go b/interpreter/value_storage_reference.go index 19ceb465a0..0f8f34c723 100644 --- a/interpreter/value_storage_reference.go +++ b/interpreter/value_storage_reference.go @@ -93,7 +93,7 @@ func (v *StorageReferenceValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v *StorageReferenceValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v *StorageReferenceValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory(interpreter, common.StorageReferenceValueStringMemoryUsage) return v.String() } @@ -324,7 +324,7 @@ func (v *StorageReferenceValue) RemoveTypeKey( RemoveTypeKey(interpreter, locationRange, key) } -func (v *StorageReferenceValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v *StorageReferenceValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherReference, ok := other.(*StorageReferenceValue) if !ok || v.TargetStorageAddress != otherReference.TargetStorageAddress || diff --git a/interpreter/value_storagecapabilitycontroller.go b/interpreter/value_storagecapabilitycontroller.go index 00f13e49e5..4764c0d5bf 100644 --- a/interpreter/value_storagecapabilitycontroller.go +++ b/interpreter/value_storagecapabilitycontroller.go @@ -160,19 +160,15 @@ func (v *StorageCapabilityControllerValue) ConformsToStaticType( return true } -func (v *StorageCapabilityControllerValue) Equal( - interpreter *Interpreter, - locationRange LocationRange, - other Value, -) bool { +func (v *StorageCapabilityControllerValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { otherController, ok := other.(*StorageCapabilityControllerValue) if !ok { return false } - return otherController.TargetPath.Equal(interpreter, locationRange, v.TargetPath) && + return otherController.TargetPath.Equal(context, locationRange, v.TargetPath) && otherController.BorrowType.Equal(v.BorrowType) && - otherController.CapabilityID.Equal(interpreter, locationRange, v.CapabilityID) + otherController.CapabilityID.Equal(context, locationRange, v.CapabilityID) } func (*StorageCapabilityControllerValue) IsStorable() bool { diff --git a/interpreter/value_string.go b/interpreter/value_string.go index 989e74d82c..42f49580b8 100644 --- a/interpreter/value_string.go +++ b/interpreter/value_string.go @@ -137,13 +137,13 @@ func (v *StringValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v *StringValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v *StringValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { l := format.FormattedStringLength(v.Str) common.UseMemory(interpreter, common.NewRawStringMemoryUsage(l)) return v.String() } -func (v *StringValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v *StringValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherString, ok := other.(*StringValue) if !ok { return false @@ -210,7 +210,7 @@ func (v *StringValue) GreaterEqual(interpreter *Interpreter, other ComparableVal // HashInput returns a byte slice containing: // - HashInputTypeString (1 byte) // - string value (n bytes) -func (v *StringValue) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v *StringValue) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { length := 1 + len(v.Str) var buffer []byte if length <= len(scratch) { diff --git a/interpreter/value_test.go b/interpreter/value_test.go index c0bbe137d1..96829d70ff 100644 --- a/interpreter/value_test.go +++ b/interpreter/value_test.go @@ -746,7 +746,7 @@ func TestOwnerDictionaryRemove(t *testing.T) { value2, ) require.IsType(t, &SomeValue{}, existingValue) - innerValue := existingValue.(*SomeValue).InnerValue(inter, EmptyLocationRange) + innerValue := existingValue.(*SomeValue).InnerValue() value1 = innerValue.(*CompositeValue) queriedValue, _ := dictionary.Get(inter, EmptyLocationRange, keyValue) @@ -804,7 +804,7 @@ func TestOwnerDictionaryInsertExisting(t *testing.T) { keyValue, ) require.IsType(t, &SomeValue{}, existingValue) - innerValue := existingValue.(*SomeValue).InnerValue(inter, EmptyLocationRange) + innerValue := existingValue.(*SomeValue).InnerValue() value = innerValue.(*CompositeValue) assert.Equal(t, newOwner, dictionary.GetOwner()) diff --git a/interpreter/value_type.go b/interpreter/value_type.go index 513f5644cb..24708c2ea3 100644 --- a/interpreter/value_type.go +++ b/interpreter/value_type.go @@ -87,7 +87,7 @@ func (v TypeValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v TypeValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v TypeValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory(interpreter, common.TypeValueStringMemoryUsage) var typeString string @@ -98,7 +98,7 @@ func (v TypeValue) MeteredString(interpreter *Interpreter, _ SeenReferences, loc return format.TypeValue(typeString) } -func (v TypeValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v TypeValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherTypeValue, ok := other.(TypeValue) if !ok { return false @@ -336,7 +336,7 @@ func (TypeValue) ChildStorables() []atree.Storable { // HashInput returns a byte slice containing: // - HashInputTypeType (1 byte) // - type id (n bytes) -func (v TypeValue) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v TypeValue) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { typeID := v.Type.ID() length := 1 + len(typeID) diff --git a/interpreter/value_ufix64.go b/interpreter/value_ufix64.go index ca7d9fd642..029fc8f7f9 100644 --- a/interpreter/value_ufix64.go +++ b/interpreter/value_ufix64.go @@ -102,7 +102,7 @@ func (v UFix64Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v UFix64Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v UFix64Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -401,7 +401,7 @@ func (v UFix64Value) GreaterEqual(interpreter *Interpreter, other ComparableValu return AsBoolValue(v >= o) } -func (v UFix64Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v UFix64Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherUFix64, ok := other.(UFix64Value) if !ok { return false @@ -412,7 +412,7 @@ func (v UFix64Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeUFix64 (1 byte) // - uint64 value encoded in big-endian (8 bytes) -func (v UFix64Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v UFix64Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeUFix64) binary.BigEndian.PutUint64(scratch[1:], uint64(v)) return scratch[:9] diff --git a/interpreter/value_uint.go b/interpreter/value_uint.go index 038fe7e172..b6d7fed1e9 100644 --- a/interpreter/value_uint.go +++ b/interpreter/value_uint.go @@ -158,7 +158,7 @@ func (v UIntValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v UIntValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v UIntValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -431,7 +431,7 @@ func (v UIntValue) GreaterEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(cmp >= 0) } -func (v UIntValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v UIntValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherUInt, ok := other.(UIntValue) if !ok { return false @@ -443,7 +443,7 @@ func (v UIntValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeUInt (1 byte) // - big int value encoded in big-endian (n bytes) -func (v UIntValue) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v UIntValue) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { b := UnsignedBigIntToBigEndianBytes(v.BigInt) length := 1 + len(b) diff --git a/interpreter/value_uint128.go b/interpreter/value_uint128.go index 8f43fb31d0..d7bf91d257 100644 --- a/interpreter/value_uint128.go +++ b/interpreter/value_uint128.go @@ -116,7 +116,7 @@ func (v UInt128Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v UInt128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v UInt128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -447,7 +447,7 @@ func (v UInt128Value) GreaterEqual(interpreter *Interpreter, other ComparableVal return AsBoolValue(cmp >= 0) } -func (v UInt128Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v UInt128Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(UInt128Value) if !ok { return false @@ -459,7 +459,7 @@ func (v UInt128Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeUInt128 (1 byte) // - big int encoded in big endian (n bytes) -func (v UInt128Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v UInt128Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { b := UnsignedBigIntToBigEndianBytes(v.BigInt) length := 1 + len(b) diff --git a/interpreter/value_uint16.go b/interpreter/value_uint16.go index 39e7281287..aa147aed8c 100644 --- a/interpreter/value_uint16.go +++ b/interpreter/value_uint16.go @@ -83,7 +83,7 @@ func (v UInt16Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v UInt16Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v UInt16Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -368,7 +368,7 @@ func (v UInt16Value) GreaterEqual(interpreter *Interpreter, other ComparableValu return AsBoolValue(v >= o) } -func (v UInt16Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v UInt16Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherUInt16, ok := other.(UInt16Value) if !ok { return false @@ -379,7 +379,7 @@ func (v UInt16Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeUInt16 (1 byte) // - uint16 value encoded in big-endian (2 bytes) -func (v UInt16Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v UInt16Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeUInt16) binary.BigEndian.PutUint16(scratch[1:], uint16(v)) return scratch[:3] diff --git a/interpreter/value_uint256.go b/interpreter/value_uint256.go index e660f8aaf0..b8d71cad17 100644 --- a/interpreter/value_uint256.go +++ b/interpreter/value_uint256.go @@ -117,7 +117,7 @@ func (v UInt256Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v UInt256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v UInt256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -449,7 +449,7 @@ func (v UInt256Value) GreaterEqual(interpreter *Interpreter, other ComparableVal return AsBoolValue(cmp >= 0) } -func (v UInt256Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v UInt256Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(UInt256Value) if !ok { return false @@ -461,7 +461,7 @@ func (v UInt256Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeUInt256 (1 byte) // - big int encoded in big endian (n bytes) -func (v UInt256Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v UInt256Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { b := UnsignedBigIntToBigEndianBytes(v.BigInt) length := 1 + len(b) diff --git a/interpreter/value_uint32.go b/interpreter/value_uint32.go index cd486c6573..d606d3bdf6 100644 --- a/interpreter/value_uint32.go +++ b/interpreter/value_uint32.go @@ -83,7 +83,7 @@ func (v UInt32Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v UInt32Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v UInt32Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -369,7 +369,7 @@ func (v UInt32Value) GreaterEqual(interpreter *Interpreter, other ComparableValu return AsBoolValue(v >= o) } -func (v UInt32Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v UInt32Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherUInt32, ok := other.(UInt32Value) if !ok { return false @@ -380,7 +380,7 @@ func (v UInt32Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeUInt32 (1 byte) // - uint32 value encoded in big-endian (4 bytes) -func (v UInt32Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v UInt32Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeUInt32) binary.BigEndian.PutUint32(scratch[1:], uint32(v)) return scratch[:5] diff --git a/interpreter/value_uint64.go b/interpreter/value_uint64.go index dc62a35143..66f0320434 100644 --- a/interpreter/value_uint64.go +++ b/interpreter/value_uint64.go @@ -90,7 +90,7 @@ func (v UInt64Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v UInt64Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v UInt64Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -399,7 +399,7 @@ func (v UInt64Value) GreaterEqual(interpreter *Interpreter, other ComparableValu return AsBoolValue(v >= o) } -func (v UInt64Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v UInt64Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherUInt64, ok := other.(UInt64Value) if !ok { return false @@ -410,7 +410,7 @@ func (v UInt64Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeUInt64 (1 byte) // - uint64 value encoded in big-endian (8 bytes) -func (v UInt64Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v UInt64Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeUInt64) binary.BigEndian.PutUint64(scratch[1:], uint64(v)) return scratch[:9] diff --git a/interpreter/value_uint8.go b/interpreter/value_uint8.go index 8dc8670de4..b992d2e965 100644 --- a/interpreter/value_uint8.go +++ b/interpreter/value_uint8.go @@ -83,7 +83,7 @@ func (v UInt8Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v UInt8Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v UInt8Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -363,7 +363,7 @@ func (v UInt8Value) GreaterEqual(interpreter *Interpreter, other ComparableValue return AsBoolValue(v >= o) } -func (v UInt8Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v UInt8Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherUInt8, ok := other.(UInt8Value) if !ok { return false @@ -374,7 +374,7 @@ func (v UInt8Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeUInt8 (1 byte) // - uint8 value (1 byte) -func (v UInt8Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v UInt8Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeUInt8) scratch[1] = byte(v) return scratch[:2] diff --git a/interpreter/value_void.go b/interpreter/value_void.go index fc452d5adc..e5e9814d3a 100644 --- a/interpreter/value_void.go +++ b/interpreter/value_void.go @@ -76,7 +76,7 @@ func (v VoidValue) ConformsToStaticType( return true } -func (v VoidValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v VoidValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { _, ok := other.(VoidValue) return ok } diff --git a/interpreter/value_word128.go b/interpreter/value_word128.go index f85eab3e0b..fe44db5690 100644 --- a/interpreter/value_word128.go +++ b/interpreter/value_word128.go @@ -116,7 +116,7 @@ func (v Word128Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Word128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Word128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -357,7 +357,7 @@ func (v Word128Value) GreaterEqual(interpreter *Interpreter, other ComparableVal return AsBoolValue(cmp >= 0) } -func (v Word128Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Word128Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(Word128Value) if !ok { return false @@ -369,7 +369,7 @@ func (v Word128Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeWord128 (1 byte) // - big int encoded in big endian (n bytes) -func (v Word128Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Word128Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { b := UnsignedBigIntToBigEndianBytes(v.BigInt) length := 1 + len(b) diff --git a/interpreter/value_word16.go b/interpreter/value_word16.go index fa8050ad0b..381c2de226 100644 --- a/interpreter/value_word16.go +++ b/interpreter/value_word16.go @@ -84,7 +84,7 @@ func (v Word16Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Word16Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Word16Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -275,7 +275,7 @@ func (v Word16Value) GreaterEqual(interpreter *Interpreter, other ComparableValu return AsBoolValue(v >= o) } -func (v Word16Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Word16Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherWord16, ok := other.(Word16Value) if !ok { return false @@ -286,7 +286,7 @@ func (v Word16Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeWord16 (1 byte) // - uint16 value encoded in big-endian (2 bytes) -func (v Word16Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Word16Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeWord16) binary.BigEndian.PutUint16(scratch[1:], uint16(v)) return scratch[:3] diff --git a/interpreter/value_word256.go b/interpreter/value_word256.go index a36cbb59d6..30ed252643 100644 --- a/interpreter/value_word256.go +++ b/interpreter/value_word256.go @@ -116,7 +116,7 @@ func (v Word256Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Word256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Word256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -357,7 +357,7 @@ func (v Word256Value) GreaterEqual(interpreter *Interpreter, other ComparableVal return AsBoolValue(cmp >= 0) } -func (v Word256Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Word256Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(Word256Value) if !ok { return false @@ -369,7 +369,7 @@ func (v Word256Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeWord256 (1 byte) // - big int encoded in big endian (n bytes) -func (v Word256Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Word256Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { b := UnsignedBigIntToBigEndianBytes(v.BigInt) length := 1 + len(b) diff --git a/interpreter/value_word32.go b/interpreter/value_word32.go index 425b52adb4..c970eb2f18 100644 --- a/interpreter/value_word32.go +++ b/interpreter/value_word32.go @@ -84,7 +84,7 @@ func (v Word32Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Word32Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Word32Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -276,7 +276,7 @@ func (v Word32Value) GreaterEqual(interpreter *Interpreter, other ComparableValu return AsBoolValue(v >= o) } -func (v Word32Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Word32Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherWord32, ok := other.(Word32Value) if !ok { return false @@ -287,7 +287,7 @@ func (v Word32Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeWord32 (1 byte) // - uint32 value encoded in big-endian (4 bytes) -func (v Word32Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Word32Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeWord32) binary.BigEndian.PutUint32(scratch[1:], uint32(v)) return scratch[:5] diff --git a/interpreter/value_word64.go b/interpreter/value_word64.go index c958e8303f..0ce12f18a5 100644 --- a/interpreter/value_word64.go +++ b/interpreter/value_word64.go @@ -92,7 +92,7 @@ func (v Word64Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Word64Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Word64Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -304,7 +304,7 @@ func (v Word64Value) GreaterEqual(interpreter *Interpreter, other ComparableValu return AsBoolValue(v >= o) } -func (v Word64Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Word64Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherWord64, ok := other.(Word64Value) if !ok { return false @@ -315,7 +315,7 @@ func (v Word64Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeWord64 (1 byte) // - uint64 value encoded in big-endian (8 bytes) -func (v Word64Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Word64Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeWord64) binary.BigEndian.PutUint64(scratch[1:], uint64(v)) return scratch[:9] diff --git a/interpreter/value_word8.go b/interpreter/value_word8.go index 932ff26ca6..080f3e980e 100644 --- a/interpreter/value_word8.go +++ b/interpreter/value_word8.go @@ -83,7 +83,7 @@ func (v Word8Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Word8Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Word8Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -275,7 +275,7 @@ func (v Word8Value) GreaterEqual(interpreter *Interpreter, other ComparableValue return AsBoolValue(v >= o) } -func (v Word8Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { +func (v Word8Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { otherWord8, ok := other.(Word8Value) if !ok { return false @@ -286,7 +286,7 @@ func (v Word8Value) Equal(_ *Interpreter, _ LocationRange, other Value) bool { // HashInput returns a byte slice containing: // - HashInputTypeWord8 (1 byte) // - uint8 value (1 byte) -func (v Word8Value) HashInput(_ *Interpreter, _ LocationRange, scratch []byte) []byte { +func (v Word8Value) HashInput(_ common.MemoryGauge, _ LocationRange, scratch []byte) []byte { scratch[0] = byte(HashInputTypeWord8) scratch[1] = byte(v) return scratch[:2] diff --git a/interpreter/values_test.go b/interpreter/values_test.go index b874aa4213..eaa0e706e3 100644 --- a/interpreter/values_test.go +++ b/interpreter/values_test.go @@ -284,7 +284,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { someValue := removedValue.(*interpreter.SomeValue) // Removed value must be same as the original value - innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := someValue.InnerValue() AssertValuesEqual(t, inter, orgValue, innerValue) return false @@ -344,7 +344,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { someValue := removedValue.(*interpreter.SomeValue) // Removed value must be same as the original value - innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := someValue.InnerValue() AssertValuesEqual(t, inter, orgValue, innerValue) return false @@ -412,7 +412,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { someValue := oldValue.(*interpreter.SomeValue) // Removed value must be same as the original value - innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := someValue.InnerValue() AssertValuesEqual(t, inter, value1, innerValue) } @@ -428,7 +428,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { someValue := readValue.(*interpreter.SomeValue) // Read value must be updated value - innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := someValue.InnerValue() AssertValuesEqual(t, inter, value2, innerValue) } }) @@ -515,7 +515,7 @@ func TestInterpretRandomMapOperations(t *testing.T) { someValue := removedValue.(*interpreter.SomeValue) // Removed value must be same as the original value - innerValue := someValue.InnerValue(inter, interpreter.EmptyLocationRange) + innerValue := someValue.InnerValue() AssertValuesEqual(t, inter, orgValue, innerValue) deleteCount++ @@ -1005,7 +1005,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { storageSize, slabCounts = getSlabStorageSize(t, storage) for fieldName, orgFieldValue := range orgFields { - fieldValue := testComposite.GetField(inter, interpreter.EmptyLocationRange, fieldName) + fieldValue := testComposite.GetField(inter, fieldName) AssertValuesEqual(t, inter, orgFieldValue, fieldValue) } @@ -1042,7 +1042,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { ).(*interpreter.CompositeValue) for name, orgValue := range orgFields { - value := copyOfTestComposite.GetField(inter, interpreter.EmptyLocationRange, name) + value := copyOfTestComposite.GetField(inter, name) AssertValuesEqual(t, inter, orgValue, value) } @@ -1062,7 +1062,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { // go over original values again and check no missing data (no side effect should be found) for name, orgValue := range orgFields { - value := testComposite.GetField(inter, interpreter.EmptyLocationRange, name) + value := testComposite.GetField(inter, name) AssertValuesEqual(t, inter, orgValue, value) } @@ -1087,7 +1087,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { for name := range orgFields { composite.RemoveField(inter, interpreter.EmptyLocationRange, name) - value := composite.GetField(inter, interpreter.EmptyLocationRange, name) + value := composite.GetField(inter, name) assert.Nil(t, value) } }) @@ -1115,7 +1115,7 @@ func TestInterpretRandomCompositeValueOperations(t *testing.T) { // Check the elements for fieldName, orgFieldValue := range fields { - fieldValue := movedComposite.GetField(inter, interpreter.EmptyLocationRange, fieldName) + fieldValue := movedComposite.GetField(inter, fieldName) AssertValuesEqual(t, inter, orgFieldValue, fieldValue) } @@ -1414,7 +1414,7 @@ func (r randomValueGenerator) generateRandomHashableValue(inter *interpreter.Int common.ZeroAddress, ) - if enum.GetField(inter, interpreter.EmptyLocationRange, sema.EnumRawValueFieldName) == nil { + if enum.GetField(inter, sema.EnumRawValueFieldName) == nil { panic("enum without raw value") } @@ -1686,7 +1686,7 @@ func (m *valueMap) internalKey(inter *interpreter.Interpreter, key interpreter.V location: key.Location, qualifiedIdentifier: key.QualifiedIdentifier, kind: key.Kind, - rawValue: key.GetField(inter, interpreter.EmptyLocationRange, sema.EnumRawValueFieldName), + rawValue: key.GetField(inter, sema.EnumRawValueFieldName), } case interpreter.Value: return key diff --git a/runtime/convertValues.go b/runtime/convertValues.go index 0de6e52513..cf3d2f405d 100644 --- a/runtime/convertValues.go +++ b/runtime/convertValues.go @@ -286,7 +286,7 @@ func exportSomeValue( cadence.Optional, error, ) { - innerValue := v.InnerValue(inter, locationRange) + innerValue := v.InnerValue() if innerValue == nil { return cadence.NewMeteredOptional(inter, nil), nil @@ -423,7 +423,7 @@ func exportCompositeValue( } case *interpreter.CompositeValue: - fieldValue = v.GetField(inter, locationRange, fieldName) + fieldValue = v.GetField(inter, fieldName) if fieldValue == nil { fieldValue = v.GetComputedField(inter, locationRange, fieldName) } @@ -637,7 +637,7 @@ func exportCompositeValueAsInclusiveRange( } getNonComputedField := func(fieldName string) (cadence.Value, error) { - fieldValue := compositeValue.GetField(inter, locationRange, fieldName) + fieldValue := compositeValue.GetField(inter, fieldName) if fieldValue == nil { // Bug if the field is absent. panic(errors.NewUnreachableError()) diff --git a/runtime/events.go b/runtime/events.go index a0e4d0bd59..3873580776 100644 --- a/runtime/events.go +++ b/runtime/events.go @@ -35,7 +35,7 @@ func emitEventValue( fields := make([]interpreter.Value, len(eventType.ConstructorParameters)) for i, parameter := range eventType.ConstructorParameters { - value := event.GetField(inter, locationRange, parameter.Identifier) + value := event.GetField(inter, parameter.Identifier) fields[i] = value } diff --git a/stdlib/test_emulatorbackend.go b/stdlib/test_emulatorbackend.go index 511621ba5d..d0dda9214f 100644 --- a/stdlib/test_emulatorbackend.go +++ b/stdlib/test_emulatorbackend.go @@ -715,7 +715,7 @@ func (t *testEmulatorBackendType) newEventsFunction( case interpreter.NilValue: // Do nothing case *interpreter.SomeValue: - innerValue := value.InnerValue(invocation.Interpreter, invocation.LocationRange) + innerValue := value.InnerValue() typeValue, ok := innerValue.(interpreter.TypeValue) if !ok { panic(errors.NewUnreachableError()) From 15f3cd01a702e0bfcfca8955ba49e91469a4b4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 2 Dec 2024 14:57:46 -0800 Subject: [PATCH 3/8] decouple Value comparison functions from Interpreter --- cmd/decode-state-values/main.go | 2 +- interpreter/inclusive_range_iterator.go | 6 ++--- interpreter/interpreter.go | 25 +++++---------------- interpreter/interpreter_expression.go | 18 +++------------ interpreter/interpreter_test.go | 30 +++++-------------------- interpreter/statictype.go | 12 ++-------- interpreter/value.go | 8 +++---- interpreter/value_array.go | 4 ++-- interpreter/value_bool.go | 10 ++++----- interpreter/value_character.go | 10 ++++----- interpreter/value_composite.go | 2 +- interpreter/value_fix64.go | 26 ++++++++++----------- interpreter/value_function.go | 4 ++-- interpreter/value_int.go | 26 ++++++++++----------- interpreter/value_int128.go | 26 ++++++++++----------- interpreter/value_int16.go | 24 ++++++++++---------- interpreter/value_int256.go | 24 ++++++++++---------- interpreter/value_int32.go | 24 ++++++++++---------- interpreter/value_int64.go | 24 ++++++++++---------- interpreter/value_int8.go | 24 ++++++++++---------- interpreter/value_nil.go | 2 +- interpreter/value_range.go | 13 ++++------- interpreter/value_some.go | 6 ++--- interpreter/value_string.go | 24 ++++++++++---------- interpreter/value_ufix64.go | 24 ++++++++++---------- interpreter/value_uint.go | 24 ++++++++++---------- interpreter/value_uint128.go | 24 ++++++++++---------- interpreter/value_uint16.go | 24 ++++++++++---------- interpreter/value_uint256.go | 24 ++++++++++---------- interpreter/value_uint32.go | 24 ++++++++++---------- interpreter/value_uint64.go | 24 ++++++++++---------- interpreter/value_uint8.go | 24 ++++++++++---------- interpreter/value_void.go | 2 +- interpreter/value_word128.go | 24 ++++++++++---------- interpreter/value_word16.go | 24 ++++++++++---------- interpreter/value_word256.go | 24 ++++++++++---------- interpreter/value_word32.go | 24 ++++++++++---------- interpreter/value_word64.go | 24 ++++++++++---------- interpreter/value_word8.go | 24 ++++++++++---------- runtime/storage_test.go | 2 +- stdlib/crypto.go | 1 - 41 files changed, 327 insertions(+), 388 deletions(-) diff --git a/cmd/decode-state-values/main.go b/cmd/decode-state-values/main.go index 99eeda2497..c803ebfaff 100644 --- a/cmd/decode-state-values/main.go +++ b/cmd/decode-state-values/main.go @@ -395,7 +395,7 @@ func loadStorageKey( if composite, ok := v.(*interpreter.CompositeValue); ok && composite.Kind == common.CompositeKindResource && - composite.ResourceUUID(inter, interpreter.EmptyLocationRange) == nil { + composite.ResourceUUID(inter) == nil { log.Printf( "Failed to get UUID for resource @ 0x%x %s", diff --git a/interpreter/inclusive_range_iterator.go b/interpreter/inclusive_range_iterator.go index 72f94cf000..1912e49bfc 100644 --- a/interpreter/inclusive_range_iterator.go +++ b/interpreter/inclusive_range_iterator.go @@ -41,12 +41,12 @@ func NewInclusiveRangeIterator( v *CompositeValue, typ InclusiveRangeStaticType, ) *InclusiveRangeIterator { - startValue := getFieldAsIntegerValue(interpreter, v, locationRange, sema.InclusiveRangeTypeStartFieldName) + startValue := getFieldAsIntegerValue(interpreter, v, sema.InclusiveRangeTypeStartFieldName) zeroValue := GetSmallIntegerValue(0, typ.ElementType) - endValue := getFieldAsIntegerValue(interpreter, v, locationRange, sema.InclusiveRangeTypeEndFieldName) + endValue := getFieldAsIntegerValue(interpreter, v, sema.InclusiveRangeTypeEndFieldName) - stepValue := getFieldAsIntegerValue(interpreter, v, locationRange, sema.InclusiveRangeTypeStepFieldName) + stepValue := getFieldAsIntegerValue(interpreter, v, sema.InclusiveRangeTypeStepFieldName) stepNegative := stepValue.Less(interpreter, zeroValue, locationRange) return &InclusiveRangeIterator{ diff --git a/interpreter/interpreter.go b/interpreter/interpreter.go index 2191054738..0417cf2abe 100644 --- a/interpreter/interpreter.go +++ b/interpreter/interpreter.go @@ -1595,13 +1595,7 @@ func (interpreter *Interpreter) declareEnumConstructor( HasPosition: declaration, } - value := EnumConstructorFunction( - interpreter, - locationRange, - compositeType, - caseValues, - constructorNestedVariables, - ) + value := EnumConstructorFunction(interpreter, compositeType, caseValues, constructorNestedVariables) variable.SetValue( interpreter, locationRange, @@ -1613,7 +1607,6 @@ func (interpreter *Interpreter) declareEnumConstructor( func EnumConstructorFunction( gauge common.MemoryGauge, - locationRange LocationRange, enumType *sema.CompositeType, cases []EnumCase, nestedVariables map[string]Variable, @@ -1907,7 +1900,7 @@ func (interpreter *Interpreter) ConvertAndBox( valueType, targetType sema.Type, ) Value { value = interpreter.convert(value, valueType, targetType, locationRange) - return interpreter.BoxOptional(locationRange, value, targetType) + return interpreter.BoxOptional(value, targetType) } // Produces the `valueStaticType` argument into a new static type that conforms @@ -2310,11 +2303,7 @@ func checkMappedEntitlements(unwrappedTargetType *sema.ReferenceType, locationRa } // BoxOptional boxes a value in optionals, if necessary -func (interpreter *Interpreter) BoxOptional( - locationRange LocationRange, - value Value, - targetType sema.Type, -) Value { +func (interpreter *Interpreter) BoxOptional(value Value, targetType sema.Type) Value { inner := value @@ -2341,7 +2330,7 @@ func (interpreter *Interpreter) BoxOptional( return value } -func (interpreter *Interpreter) Unbox(locationRange LocationRange, value Value) Value { +func (interpreter *Interpreter) Unbox(value Value) Value { for { some, ok := value.(*SomeValue) if !ok { @@ -4707,11 +4696,7 @@ func (interpreter *Interpreter) MustConvertStaticToSemaType(staticType StaticTyp } func (interpreter *Interpreter) MustConvertStaticAuthorizationToSemaAccess(auth Authorization) sema.Access { - access, err := ConvertStaticAuthorizationToSemaAccess( - interpreter, - auth, - interpreter, - ) + access, err := ConvertStaticAuthorizationToSemaAccess(auth, interpreter) if err != nil { panic(err) } diff --git a/interpreter/interpreter_expression.go b/interpreter/interpreter_expression.go index bd449c6d61..60f0232100 100644 --- a/interpreter/interpreter_expression.go +++ b/interpreter/interpreter_expression.go @@ -662,21 +662,9 @@ func (interpreter *Interpreter) VisitBinaryExpression(expression *ast.BinaryExpr } func (interpreter *Interpreter) testEqual(left, right Value, expression *ast.BinaryExpression) BoolValue { - left = interpreter.Unbox( - LocationRange{ - Location: interpreter.Location, - HasPosition: expression.Left, - }, - left, - ) + left = interpreter.Unbox(left) - right = interpreter.Unbox( - LocationRange{ - Location: interpreter.Location, - HasPosition: expression.Right, - }, - right, - ) + right = interpreter.Unbox(right) leftEquatable, ok := left.(EquatableValue) if !ok { @@ -1371,7 +1359,7 @@ func (interpreter *Interpreter) VisitCastingExpression(expression *ast.CastingEx unboxedExpectedType := sema.UnwrapOptionalType(expectedType) if !(unboxedExpectedType == sema.AnyStructType || unboxedExpectedType == sema.AnyResourceType) { // otherwise dynamic cast now always unboxes optionals - value = interpreter.Unbox(locationRange, value) + value = interpreter.Unbox(value) } valueSemaType := interpreter.SubstituteMappedEntitlements(interpreter.MustSemaTypeOfValue(value)) valueStaticType := ConvertSemaToStaticType(interpreter, valueSemaType) diff --git a/interpreter/interpreter_test.go b/interpreter/interpreter_test.go index f69e7d77ea..010e6a98e9 100644 --- a/interpreter/interpreter_test.go +++ b/interpreter/interpreter_test.go @@ -36,11 +36,7 @@ func TestInterpreterOptionalBoxing(t *testing.T) { t.Run("Bool to Bool?", func(t *testing.T) { inter := newTestInterpreter(t) - value := inter.BoxOptional( - EmptyLocationRange, - TrueValue, - &sema.OptionalType{Type: sema.BoolType}, - ) + value := inter.BoxOptional(TrueValue, &sema.OptionalType{Type: sema.BoolType}) assert.Equal(t, NewUnmeteredSomeValueNonCopying(TrueValue), value, @@ -50,11 +46,7 @@ func TestInterpreterOptionalBoxing(t *testing.T) { t.Run("Bool? to Bool?", func(t *testing.T) { inter := newTestInterpreter(t) - value := inter.BoxOptional( - EmptyLocationRange, - NewUnmeteredSomeValueNonCopying(TrueValue), - &sema.OptionalType{Type: sema.BoolType}, - ) + value := inter.BoxOptional(NewUnmeteredSomeValueNonCopying(TrueValue), &sema.OptionalType{Type: sema.BoolType}) assert.Equal(t, NewUnmeteredSomeValueNonCopying(TrueValue), value, @@ -64,11 +56,7 @@ func TestInterpreterOptionalBoxing(t *testing.T) { t.Run("Bool? to Bool??", func(t *testing.T) { inter := newTestInterpreter(t) - value := inter.BoxOptional( - EmptyLocationRange, - NewUnmeteredSomeValueNonCopying(TrueValue), - &sema.OptionalType{Type: &sema.OptionalType{Type: sema.BoolType}}, - ) + value := inter.BoxOptional(NewUnmeteredSomeValueNonCopying(TrueValue), &sema.OptionalType{Type: &sema.OptionalType{Type: sema.BoolType}}) assert.Equal(t, NewUnmeteredSomeValueNonCopying( NewUnmeteredSomeValueNonCopying(TrueValue), @@ -81,11 +69,7 @@ func TestInterpreterOptionalBoxing(t *testing.T) { inter := newTestInterpreter(t) // NOTE: - value := inter.BoxOptional( - EmptyLocationRange, - Nil, - &sema.OptionalType{Type: &sema.OptionalType{Type: sema.BoolType}}, - ) + value := inter.BoxOptional(Nil, &sema.OptionalType{Type: &sema.OptionalType{Type: sema.BoolType}}) assert.Equal(t, Nil, value, @@ -96,11 +80,7 @@ func TestInterpreterOptionalBoxing(t *testing.T) { inter := newTestInterpreter(t) // NOTE: - value := inter.BoxOptional( - EmptyLocationRange, - NewUnmeteredSomeValueNonCopying(Nil), - &sema.OptionalType{Type: &sema.OptionalType{Type: sema.BoolType}}, - ) + value := inter.BoxOptional(NewUnmeteredSomeValueNonCopying(Nil), &sema.OptionalType{Type: &sema.OptionalType{Type: sema.BoolType}}) assert.Equal(t, Nil, value, diff --git a/interpreter/statictype.go b/interpreter/statictype.go index c2de979eea..254bb3189f 100644 --- a/interpreter/statictype.go +++ b/interpreter/statictype.go @@ -1166,13 +1166,9 @@ func ConvertSemaInterfaceTypeToStaticInterfaceType( } func ConvertStaticAuthorizationToSemaAccess( - memoryGauge common.MemoryGauge, auth Authorization, handler StaticAuthorizationConversionHandler, -) ( - sema.Access, - error, -) { +) (sema.Access, error) { switch auth := auth.(type) { case Unauthorized: @@ -1364,11 +1360,7 @@ func ConvertStaticToSemaType( return nil, err } - access, err := ConvertStaticAuthorizationToSemaAccess( - memoryGauge, - t.Authorization, - handler, - ) + access, err := ConvertStaticAuthorizationToSemaAccess(t.Authorization, handler) if err != nil { return nil, err diff --git a/interpreter/value.go b/interpreter/value.go index c0e71ca2db..fe9bd9978e 100644 --- a/interpreter/value.go +++ b/interpreter/value.go @@ -179,10 +179,10 @@ func newValueComparator(context ComparisonContext, locationRange LocationRange) // ComparableValue type ComparableValue interface { EquatableValue - Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue - LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue - Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue - GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue + Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue + LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue + Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue + GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue } // ResourceKindedValue diff --git a/interpreter/value_array.go b/interpreter/value_array.go index b420bea33a..d1c9df382f 100644 --- a/interpreter/value_array.go +++ b/interpreter/value_array.go @@ -1170,12 +1170,12 @@ func (v *ArrayValue) GetMember(interpreter *Interpreter, _ LocationRange, name s return nil } -func (v *ArrayValue) RemoveMember(interpreter *Interpreter, locationRange LocationRange, _ string) Value { +func (v *ArrayValue) RemoveMember(_ *Interpreter, _ LocationRange, _ string) Value { // Arrays have no removable members (fields / functions) panic(errors.NewUnreachableError()) } -func (v *ArrayValue) SetMember(interpreter *Interpreter, locationRange LocationRange, _ string, _ Value) bool { +func (v *ArrayValue) SetMember(_ *Interpreter, _ LocationRange, _ string, _ Value) bool { // Arrays have no settable members (fields / functions) panic(errors.NewUnreachableError()) } diff --git a/interpreter/value_bool.go b/interpreter/value_bool.go index ebdd8969fb..e0018f77f9 100644 --- a/interpreter/value_bool.go +++ b/interpreter/value_bool.go @@ -79,7 +79,7 @@ func (v BoolValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool return bool(v) == bool(otherBool) } -func (v BoolValue) Less(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { +func (v BoolValue) Less(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -88,7 +88,7 @@ func (v BoolValue) Less(_ *Interpreter, other ComparableValue, _ LocationRange) return !v && o } -func (v BoolValue) LessEqual(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { +func (v BoolValue) LessEqual(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -97,7 +97,7 @@ func (v BoolValue) LessEqual(_ *Interpreter, other ComparableValue, _ LocationRa return !v || o } -func (v BoolValue) Greater(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { +func (v BoolValue) Greater(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -106,7 +106,7 @@ func (v BoolValue) Greater(_ *Interpreter, other ComparableValue, _ LocationRang return v && !o } -func (v BoolValue) GreaterEqual(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { +func (v BoolValue) GreaterEqual(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -136,7 +136,7 @@ func (v BoolValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v BoolValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v BoolValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { if v { common.UseMemory(interpreter, common.TrueStringMemoryUsage) } else { diff --git a/interpreter/value_character.go b/interpreter/value_character.go index 528458cc6a..b5a1491d0f 100644 --- a/interpreter/value_character.go +++ b/interpreter/value_character.go @@ -102,7 +102,7 @@ func (v CharacterValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v CharacterValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v CharacterValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { l := format.FormattedStringLength(v.Str) common.UseMemory(interpreter, common.NewRawStringMemoryUsage(l)) return v.String() @@ -116,7 +116,7 @@ func (v CharacterValue) Equal(_ ComparisonContext, _ LocationRange, other Value) return v.Str == otherChar.Str } -func (v CharacterValue) Less(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { +func (v CharacterValue) Less(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) @@ -124,7 +124,7 @@ func (v CharacterValue) Less(_ *Interpreter, other ComparableValue, _ LocationRa return v.Str < otherChar.Str } -func (v CharacterValue) LessEqual(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { +func (v CharacterValue) LessEqual(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) @@ -132,7 +132,7 @@ func (v CharacterValue) LessEqual(_ *Interpreter, other ComparableValue, _ Locat return v.Str <= otherChar.Str } -func (v CharacterValue) Greater(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { +func (v CharacterValue) Greater(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) @@ -140,7 +140,7 @@ func (v CharacterValue) Greater(_ *Interpreter, other ComparableValue, _ Locatio return v.Str > otherChar.Str } -func (v CharacterValue) GreaterEqual(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { +func (v CharacterValue) GreaterEqual(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) diff --git a/interpreter/value_composite.go b/interpreter/value_composite.go index 684427469f..a92dd86180 100644 --- a/interpreter/value_composite.go +++ b/interpreter/value_composite.go @@ -1350,7 +1350,7 @@ func (v *CompositeValue) Transfer( return res } -func (v *CompositeValue) ResourceUUID(interpreter *Interpreter, locationRange LocationRange) *UInt64Value { +func (v *CompositeValue) ResourceUUID(interpreter *Interpreter) *UInt64Value { fieldValue := v.GetField(interpreter, sema.ResourceUUIDFieldName) uuid, ok := fieldValue.(UInt64Value) if !ok { diff --git a/interpreter/value_fix64.go b/interpreter/value_fix64.go index 827f538b6f..cfd8d7bbf0 100644 --- a/interpreter/value_fix64.go +++ b/interpreter/value_fix64.go @@ -109,7 +109,7 @@ func (v Fix64Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Fix64Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Fix64Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -400,13 +400,13 @@ func (v Fix64Value) Mod(interpreter *Interpreter, other NumberValue, locationRan ) } -func (v Fix64Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Fix64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -414,13 +414,13 @@ func (v Fix64Value) Less(interpreter *Interpreter, other ComparableValue, locati return AsBoolValue(v < o) } -func (v Fix64Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Fix64Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -428,13 +428,13 @@ func (v Fix64Value) LessEqual(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(v <= o) } -func (v Fix64Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Fix64Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -442,13 +442,13 @@ func (v Fix64Value) Greater(interpreter *Interpreter, other ComparableValue, loc return AsBoolValue(v > o) } -func (v Fix64Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Fix64Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_function.go b/interpreter/value_function.go index 9240699bee..2d17d4a0ab 100644 --- a/interpreter/value_function.go +++ b/interpreter/value_function.go @@ -88,7 +88,7 @@ func (f *InterpretedFunctionValue) RecursiveString(_ SeenReferences) string { return f.String() } -func (f *InterpretedFunctionValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (f *InterpretedFunctionValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { // TODO: Meter sema.Type String conversion typeString := f.Type.String() common.UseMemory(interpreter, common.NewRawStringMemoryUsage(8+len(typeString))) @@ -186,7 +186,7 @@ func (f *HostFunctionValue) RecursiveString(_ SeenReferences) string { return f.String() } -func (f *HostFunctionValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (f *HostFunctionValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory(interpreter, common.HostFunctionValueStringMemoryUsage) return f.String() } diff --git a/interpreter/value_int.go b/interpreter/value_int.go index 1643f2062c..ddf2c5d6db 100644 --- a/interpreter/value_int.go +++ b/interpreter/value_int.go @@ -161,7 +161,7 @@ func (v IntValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v IntValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v IntValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -362,13 +362,13 @@ func (v IntValue) SaturatingDiv(interpreter *Interpreter, other NumberValue, loc return v.Div(interpreter, other, locationRange) } -func (v IntValue) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v IntValue) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -377,13 +377,13 @@ func (v IntValue) Less(interpreter *Interpreter, other ComparableValue, location return AsBoolValue(cmp == -1) } -func (v IntValue) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v IntValue) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -392,13 +392,13 @@ func (v IntValue) LessEqual(interpreter *Interpreter, other ComparableValue, loc return AsBoolValue(cmp <= 0) } -func (v IntValue) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v IntValue) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -408,13 +408,13 @@ func (v IntValue) Greater(interpreter *Interpreter, other ComparableValue, locat } -func (v IntValue) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v IntValue) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_int128.go b/interpreter/value_int128.go index 529c5a2bf7..8e6fdcf577 100644 --- a/interpreter/value_int128.go +++ b/interpreter/value_int128.go @@ -116,7 +116,7 @@ func (v Int128Value) RecursiveString(_ SeenReferences) string { return v.String() } -func (v Int128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v Int128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory( interpreter, common.NewRawStringMemoryUsage( @@ -461,13 +461,13 @@ func (v Int128Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, return NewInt128ValueFromBigInt(interpreter, valueGetter) } -func (v Int128Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int128Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -476,13 +476,13 @@ func (v Int128Value) Less(interpreter *Interpreter, other ComparableValue, locat return AsBoolValue(cmp == -1) } -func (v Int128Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int128Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -491,13 +491,13 @@ func (v Int128Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(cmp <= 0) } -func (v Int128Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int128Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -506,13 +506,13 @@ func (v Int128Value) Greater(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(cmp == 1) } -func (v Int128Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int128Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_int16.go b/interpreter/value_int16.go index 9851d73ada..2d1c7028d2 100644 --- a/interpreter/value_int16.go +++ b/interpreter/value_int16.go @@ -399,13 +399,13 @@ func (v Int16Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l return NewInt16Value(interpreter, valueGetter) } -func (v Int16Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int16Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -413,13 +413,13 @@ func (v Int16Value) Less(interpreter *Interpreter, other ComparableValue, locati return AsBoolValue(v < o) } -func (v Int16Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int16Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -427,13 +427,13 @@ func (v Int16Value) LessEqual(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(v <= o) } -func (v Int16Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int16Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -441,13 +441,13 @@ func (v Int16Value) Greater(interpreter *Interpreter, other ComparableValue, loc return AsBoolValue(v > o) } -func (v Int16Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int16Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_int256.go b/interpreter/value_int256.go index fcd76b6018..d257629b91 100644 --- a/interpreter/value_int256.go +++ b/interpreter/value_int256.go @@ -459,13 +459,13 @@ func (v Int256Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, return NewInt256ValueFromBigInt(interpreter, valueGetter) } -func (v Int256Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int256Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -474,13 +474,13 @@ func (v Int256Value) Less(interpreter *Interpreter, other ComparableValue, locat return AsBoolValue(cmp == -1) } -func (v Int256Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int256Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -489,13 +489,13 @@ func (v Int256Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(cmp <= 0) } -func (v Int256Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int256Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -504,13 +504,13 @@ func (v Int256Value) Greater(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(cmp == 1) } -func (v Int256Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int256Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_int32.go b/interpreter/value_int32.go index 194866fc1c..14c79848c9 100644 --- a/interpreter/value_int32.go +++ b/interpreter/value_int32.go @@ -400,13 +400,13 @@ func (v Int32Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l return NewInt32Value(interpreter, valueGetter) } -func (v Int32Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int32Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -414,13 +414,13 @@ func (v Int32Value) Less(interpreter *Interpreter, other ComparableValue, locati return AsBoolValue(v < o) } -func (v Int32Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int32Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -428,13 +428,13 @@ func (v Int32Value) LessEqual(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(v <= o) } -func (v Int32Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int32Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -442,13 +442,13 @@ func (v Int32Value) Greater(interpreter *Interpreter, other ComparableValue, loc return AsBoolValue(v > o) } -func (v Int32Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int32Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_int64.go b/interpreter/value_int64.go index a4f216c6aa..86863b8853 100644 --- a/interpreter/value_int64.go +++ b/interpreter/value_int64.go @@ -399,13 +399,13 @@ func (v Int64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l return NewInt64Value(interpreter, valueGetter) } -func (v Int64Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -413,13 +413,13 @@ func (v Int64Value) Less(interpreter *Interpreter, other ComparableValue, locati return AsBoolValue(v < o) } -func (v Int64Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int64Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -427,13 +427,13 @@ func (v Int64Value) LessEqual(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(v <= o) } -func (v Int64Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int64Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -442,13 +442,13 @@ func (v Int64Value) Greater(interpreter *Interpreter, other ComparableValue, loc } -func (v Int64Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int64Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_int8.go b/interpreter/value_int8.go index b3aff29499..1411687883 100644 --- a/interpreter/value_int8.go +++ b/interpreter/value_int8.go @@ -398,13 +398,13 @@ func (v Int8Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, lo return NewInt8Value(interpreter, valueGetter) } -func (v Int8Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int8Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -412,13 +412,13 @@ func (v Int8Value) Less(interpreter *Interpreter, other ComparableValue, locatio return AsBoolValue(v < o) } -func (v Int8Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int8Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -426,13 +426,13 @@ func (v Int8Value) LessEqual(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(v <= o) } -func (v Int8Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int8Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -440,13 +440,13 @@ func (v Int8Value) Greater(interpreter *Interpreter, other ComparableValue, loca return AsBoolValue(v > o) } -func (v Int8Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int8Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_nil.go b/interpreter/value_nil.go index a94006aaa2..40d1029f71 100644 --- a/interpreter/value_nil.go +++ b/interpreter/value_nil.go @@ -84,7 +84,7 @@ func (v NilValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v NilValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v NilValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory(interpreter, common.NilValueStringMemoryUsage) return v.String() } diff --git a/interpreter/value_range.go b/interpreter/value_range.go index fb6d780a76..4bcb35b10f 100644 --- a/interpreter/value_range.go +++ b/interpreter/value_range.go @@ -194,9 +194,9 @@ func rangeContains( locationRange LocationRange, needleValue IntegerValue, ) BoolValue { - start := getFieldAsIntegerValue(interpreter, rangeValue, locationRange, sema.InclusiveRangeTypeStartFieldName) - end := getFieldAsIntegerValue(interpreter, rangeValue, locationRange, sema.InclusiveRangeTypeEndFieldName) - step := getFieldAsIntegerValue(interpreter, rangeValue, locationRange, sema.InclusiveRangeTypeStepFieldName) + start := getFieldAsIntegerValue(interpreter, rangeValue, sema.InclusiveRangeTypeStartFieldName) + end := getFieldAsIntegerValue(interpreter, rangeValue, sema.InclusiveRangeTypeEndFieldName) + step := getFieldAsIntegerValue(interpreter, rangeValue, sema.InclusiveRangeTypeStepFieldName) result := start.Equal(interpreter, locationRange, needleValue) || end.Equal(interpreter, locationRange, needleValue) @@ -224,12 +224,7 @@ func rangeContains( return AsBoolValue(result) } -func getFieldAsIntegerValue( - interpreter *Interpreter, - rangeValue *CompositeValue, - locationRange LocationRange, - name string, -) IntegerValue { +func getFieldAsIntegerValue(interpreter *Interpreter, rangeValue *CompositeValue, name string) IntegerValue { return convertAndAssertIntegerValue( rangeValue.GetField(interpreter, name), ) diff --git a/interpreter/value_some.go b/interpreter/value_some.go index 854a9785e0..be1f5c4466 100644 --- a/interpreter/value_some.go +++ b/interpreter/value_some.go @@ -167,11 +167,11 @@ func (v *SomeValue) GetMember(interpreter *Interpreter, _ LocationRange, name st return nil } -func (v *SomeValue) RemoveMember(interpreter *Interpreter, locationRange LocationRange, _ string) Value { +func (v *SomeValue) RemoveMember(_ *Interpreter, _ LocationRange, _ string) Value { panic(errors.NewUnreachableError()) } -func (v *SomeValue) SetMember(interpreter *Interpreter, locationRange LocationRange, _ string, _ Value) bool { +func (v *SomeValue) SetMember(_ *Interpreter, _ LocationRange, _ string, _ Value) bool { panic(errors.NewUnreachableError()) } @@ -369,7 +369,7 @@ func (v *SomeValue) InnerValue() Value { return v.value } -func (v *SomeValue) isInvalidatedResource(interpreter *Interpreter) bool { +func (v *SomeValue) isInvalidatedResource(_ *Interpreter) bool { return v.value == nil || v.IsDestroyed() } diff --git a/interpreter/value_string.go b/interpreter/value_string.go index 42f49580b8..4e07286b57 100644 --- a/interpreter/value_string.go +++ b/interpreter/value_string.go @@ -151,13 +151,13 @@ func (v *StringValue) Equal(_ ComparisonContext, _ LocationRange, other Value) b return v.Str == otherString.Str } -func (v *StringValue) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v *StringValue) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -165,13 +165,13 @@ func (v *StringValue) Less(interpreter *Interpreter, other ComparableValue, loca return AsBoolValue(v.Str < otherString.Str) } -func (v *StringValue) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v *StringValue) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -179,13 +179,13 @@ func (v *StringValue) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(v.Str <= otherString.Str) } -func (v *StringValue) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v *StringValue) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -193,13 +193,13 @@ func (v *StringValue) Greater(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(v.Str > otherString.Str) } -func (v *StringValue) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v *StringValue) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_ufix64.go b/interpreter/value_ufix64.go index 029fc8f7f9..571257d364 100644 --- a/interpreter/value_ufix64.go +++ b/interpreter/value_ufix64.go @@ -345,13 +345,13 @@ func (v UFix64Value) Mod(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UFix64Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UFix64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -359,13 +359,13 @@ func (v UFix64Value) Less(interpreter *Interpreter, other ComparableValue, locat return AsBoolValue(v < o) } -func (v UFix64Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UFix64Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -373,13 +373,13 @@ func (v UFix64Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(v <= o) } -func (v UFix64Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UFix64Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -387,13 +387,13 @@ func (v UFix64Value) Greater(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(v > o) } -func (v UFix64Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UFix64Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_uint.go b/interpreter/value_uint.go index b6d7fed1e9..e1a9422c09 100644 --- a/interpreter/value_uint.go +++ b/interpreter/value_uint.go @@ -371,13 +371,13 @@ func (v UIntValue) SaturatingDiv(interpreter *Interpreter, other NumberValue, lo return v.Div(interpreter, other, locationRange) } -func (v UIntValue) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UIntValue) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -386,13 +386,13 @@ func (v UIntValue) Less(interpreter *Interpreter, other ComparableValue, locatio return AsBoolValue(cmp == -1) } -func (v UIntValue) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UIntValue) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -401,13 +401,13 @@ func (v UIntValue) LessEqual(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(cmp <= 0) } -func (v UIntValue) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UIntValue) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -416,13 +416,13 @@ func (v UIntValue) Greater(interpreter *Interpreter, other ComparableValue, loca return AsBoolValue(cmp == 1) } -func (v UIntValue) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UIntValue) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_uint128.go b/interpreter/value_uint128.go index d7bf91d257..7ac30e7aae 100644 --- a/interpreter/value_uint128.go +++ b/interpreter/value_uint128.go @@ -387,13 +387,13 @@ func (v UInt128Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, return v.Div(interpreter, other, locationRange) } -func (v UInt128Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt128Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -402,13 +402,13 @@ func (v UInt128Value) Less(interpreter *Interpreter, other ComparableValue, loca return AsBoolValue(cmp == -1) } -func (v UInt128Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt128Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -417,13 +417,13 @@ func (v UInt128Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(cmp <= 0) } -func (v UInt128Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt128Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -432,13 +432,13 @@ func (v UInt128Value) Greater(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(cmp == 1) } -func (v UInt128Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt128Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_uint16.go b/interpreter/value_uint16.go index aa147aed8c..90385be62c 100644 --- a/interpreter/value_uint16.go +++ b/interpreter/value_uint16.go @@ -312,13 +312,13 @@ func (v UInt16Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, return v.Div(interpreter, other, locationRange) } -func (v UInt16Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt16Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -326,13 +326,13 @@ func (v UInt16Value) Less(interpreter *Interpreter, other ComparableValue, locat return AsBoolValue(v < o) } -func (v UInt16Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt16Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -340,13 +340,13 @@ func (v UInt16Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(v <= o) } -func (v UInt16Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt16Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -354,13 +354,13 @@ func (v UInt16Value) Greater(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(v > o) } -func (v UInt16Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt16Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_uint256.go b/interpreter/value_uint256.go index b8d71cad17..a1355e8465 100644 --- a/interpreter/value_uint256.go +++ b/interpreter/value_uint256.go @@ -389,13 +389,13 @@ func (v UInt256Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, return v.Div(interpreter, other, locationRange) } -func (v UInt256Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt256Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -404,13 +404,13 @@ func (v UInt256Value) Less(interpreter *Interpreter, other ComparableValue, loca return AsBoolValue(cmp == -1) } -func (v UInt256Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt256Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -419,13 +419,13 @@ func (v UInt256Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(cmp <= 0) } -func (v UInt256Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt256Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -434,13 +434,13 @@ func (v UInt256Value) Greater(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(cmp == 1) } -func (v UInt256Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt256Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_uint32.go b/interpreter/value_uint32.go index d606d3bdf6..88f0b82e61 100644 --- a/interpreter/value_uint32.go +++ b/interpreter/value_uint32.go @@ -313,13 +313,13 @@ func (v UInt32Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, return v.Div(interpreter, other, locationRange) } -func (v UInt32Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt32Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -327,13 +327,13 @@ func (v UInt32Value) Less(interpreter *Interpreter, other ComparableValue, locat return AsBoolValue(v < o) } -func (v UInt32Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt32Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -341,13 +341,13 @@ func (v UInt32Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(v <= o) } -func (v UInt32Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt32Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -355,13 +355,13 @@ func (v UInt32Value) Greater(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(v > o) } -func (v UInt32Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt32Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_uint64.go b/interpreter/value_uint64.go index 66f0320434..d1c736bca6 100644 --- a/interpreter/value_uint64.go +++ b/interpreter/value_uint64.go @@ -343,13 +343,13 @@ func (v UInt64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, return v.Div(interpreter, other, locationRange) } -func (v UInt64Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -357,13 +357,13 @@ func (v UInt64Value) Less(interpreter *Interpreter, other ComparableValue, locat return AsBoolValue(v < o) } -func (v UInt64Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt64Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -371,13 +371,13 @@ func (v UInt64Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(v <= o) } -func (v UInt64Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt64Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -385,13 +385,13 @@ func (v UInt64Value) Greater(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(v > o) } -func (v UInt64Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt64Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_uint8.go b/interpreter/value_uint8.go index b992d2e965..a9916b3749 100644 --- a/interpreter/value_uint8.go +++ b/interpreter/value_uint8.go @@ -307,13 +307,13 @@ func (v UInt8Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l return v.Div(interpreter, other, locationRange) } -func (v UInt8Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt8Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -321,13 +321,13 @@ func (v UInt8Value) Less(interpreter *Interpreter, other ComparableValue, locati return AsBoolValue(v < o) } -func (v UInt8Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt8Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -335,13 +335,13 @@ func (v UInt8Value) LessEqual(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(v <= o) } -func (v UInt8Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt8Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -349,13 +349,13 @@ func (v UInt8Value) Greater(interpreter *Interpreter, other ComparableValue, loc return AsBoolValue(v > o) } -func (v UInt8Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt8Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_void.go b/interpreter/value_void.go index e5e9814d3a..d7ebc5dc56 100644 --- a/interpreter/value_void.go +++ b/interpreter/value_void.go @@ -63,7 +63,7 @@ func (v VoidValue) RecursiveString(_ SeenReferences) string { return v.String() } -func (v VoidValue) MeteredString(interpreter *Interpreter, _ SeenReferences, locationRange LocationRange) string { +func (v VoidValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ LocationRange) string { common.UseMemory(interpreter, common.VoidStringMemoryUsage) return v.String() } diff --git a/interpreter/value_word128.go b/interpreter/value_word128.go index fe44db5690..e4e4937fd6 100644 --- a/interpreter/value_word128.go +++ b/interpreter/value_word128.go @@ -297,13 +297,13 @@ func (v Word128Value) SaturatingDiv(_ *Interpreter, _ NumberValue, _ LocationRan panic(errors.NewUnreachableError()) } -func (v Word128Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word128Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -312,13 +312,13 @@ func (v Word128Value) Less(interpreter *Interpreter, other ComparableValue, loca return AsBoolValue(cmp == -1) } -func (v Word128Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word128Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -327,13 +327,13 @@ func (v Word128Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(cmp <= 0) } -func (v Word128Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word128Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -342,13 +342,13 @@ func (v Word128Value) Greater(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(cmp == 1) } -func (v Word128Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word128Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_word16.go b/interpreter/value_word16.go index 381c2de226..78b4e640e4 100644 --- a/interpreter/value_word16.go +++ b/interpreter/value_word16.go @@ -219,13 +219,13 @@ func (v Word16Value) SaturatingDiv(*Interpreter, NumberValue, LocationRange) Num panic(errors.NewUnreachableError()) } -func (v Word16Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word16Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -233,13 +233,13 @@ func (v Word16Value) Less(interpreter *Interpreter, other ComparableValue, locat return AsBoolValue(v < o) } -func (v Word16Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word16Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -247,13 +247,13 @@ func (v Word16Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(v <= o) } -func (v Word16Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word16Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -261,13 +261,13 @@ func (v Word16Value) Greater(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(v > o) } -func (v Word16Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word16Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_word256.go b/interpreter/value_word256.go index 30ed252643..d40ab268c0 100644 --- a/interpreter/value_word256.go +++ b/interpreter/value_word256.go @@ -297,13 +297,13 @@ func (v Word256Value) SaturatingDiv(_ *Interpreter, _ NumberValue, _ LocationRan panic(errors.NewUnreachableError()) } -func (v Word256Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word256Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -312,13 +312,13 @@ func (v Word256Value) Less(interpreter *Interpreter, other ComparableValue, loca return AsBoolValue(cmp == -1) } -func (v Word256Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word256Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -327,13 +327,13 @@ func (v Word256Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(cmp <= 0) } -func (v Word256Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word256Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -342,13 +342,13 @@ func (v Word256Value) Greater(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(cmp == 1) } -func (v Word256Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word256Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_word32.go b/interpreter/value_word32.go index c970eb2f18..cd2a6e75d5 100644 --- a/interpreter/value_word32.go +++ b/interpreter/value_word32.go @@ -220,13 +220,13 @@ func (v Word32Value) SaturatingDiv(*Interpreter, NumberValue, LocationRange) Num panic(errors.NewUnreachableError()) } -func (v Word32Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word32Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -234,13 +234,13 @@ func (v Word32Value) Less(interpreter *Interpreter, other ComparableValue, locat return AsBoolValue(v < o) } -func (v Word32Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word32Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -248,13 +248,13 @@ func (v Word32Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(v <= o) } -func (v Word32Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word32Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -262,13 +262,13 @@ func (v Word32Value) Greater(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(v > o) } -func (v Word32Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word32Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_word64.go b/interpreter/value_word64.go index 0ce12f18a5..feee5d2efa 100644 --- a/interpreter/value_word64.go +++ b/interpreter/value_word64.go @@ -248,13 +248,13 @@ func (v Word64Value) SaturatingDiv(*Interpreter, NumberValue, LocationRange) Num panic(errors.NewUnreachableError()) } -func (v Word64Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -262,13 +262,13 @@ func (v Word64Value) Less(interpreter *Interpreter, other ComparableValue, locat return AsBoolValue(v < o) } -func (v Word64Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word64Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -276,13 +276,13 @@ func (v Word64Value) LessEqual(interpreter *Interpreter, other ComparableValue, return AsBoolValue(v <= o) } -func (v Word64Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word64Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -290,13 +290,13 @@ func (v Word64Value) Greater(interpreter *Interpreter, other ComparableValue, lo return AsBoolValue(v > o) } -func (v Word64Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word64Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/interpreter/value_word8.go b/interpreter/value_word8.go index 080f3e980e..714e38b86a 100644 --- a/interpreter/value_word8.go +++ b/interpreter/value_word8.go @@ -219,13 +219,13 @@ func (v Word8Value) SaturatingDiv(*Interpreter, NumberValue, LocationRange) Numb panic(errors.NewUnreachableError()) } -func (v Word8Value) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word8Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -233,13 +233,13 @@ func (v Word8Value) Less(interpreter *Interpreter, other ComparableValue, locati return AsBoolValue(v < o) } -func (v Word8Value) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word8Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -247,13 +247,13 @@ func (v Word8Value) LessEqual(interpreter *Interpreter, other ComparableValue, l return AsBoolValue(v <= o) } -func (v Word8Value) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word8Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -261,13 +261,13 @@ func (v Word8Value) Greater(interpreter *Interpreter, other ComparableValue, loc return AsBoolValue(v > o) } -func (v Word8Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word8Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } diff --git a/runtime/storage_test.go b/runtime/storage_test.go index aedd492c11..804bcdc7d9 100644 --- a/runtime/storage_test.go +++ b/runtime/storage_test.go @@ -1676,7 +1676,7 @@ func TestRuntimeResourceOwnerChange(t *testing.T) { resourceOwnerChange{ typeID: resource.TypeID(), // TODO: provide proper location range - uuid: resource.ResourceUUID(inter, interpreter.EmptyLocationRange), + uuid: resource.ResourceUUID(inter), oldAddress: oldAddress, newAddress: newAddress, }, diff --git a/stdlib/crypto.go b/stdlib/crypto.go index c8838a474b..1f14765f5b 100644 --- a/stdlib/crypto.go +++ b/stdlib/crypto.go @@ -89,7 +89,6 @@ func cryptoAlgorithmEnumValueAndCaseValues[T sema.CryptoAlgorithm]( value = interpreter.EnumConstructorFunction( nil, - interpreter.EmptyLocationRange, enumType, caseValues, constructorNestedVariables, From d8af8f228a1a2e19d687b341119df7f61e62a90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 2 Dec 2024 15:38:52 -0800 Subject: [PATCH 4/8] decouple arithmetic functions on number values from Interpreter --- interpreter/interface.go | 6 +++ interpreter/value_fix64.go | 86 ++++++++++++++++++------------------ interpreter/value_int.go | 76 +++++++++++++++---------------- interpreter/value_int128.go | 76 +++++++++++++++---------------- interpreter/value_int16.go | 76 +++++++++++++++---------------- interpreter/value_int256.go | 76 +++++++++++++++---------------- interpreter/value_int32.go | 76 +++++++++++++++---------------- interpreter/value_int64.go | 76 +++++++++++++++---------------- interpreter/value_int8.go | 76 +++++++++++++++---------------- interpreter/value_number.go | 20 ++++----- interpreter/value_ufix64.go | 84 +++++++++++++++++------------------ interpreter/value_uint.go | 74 +++++++++++++++---------------- interpreter/value_uint128.go | 74 +++++++++++++++---------------- interpreter/value_uint16.go | 74 +++++++++++++++---------------- interpreter/value_uint256.go | 74 +++++++++++++++---------------- interpreter/value_uint32.go | 74 +++++++++++++++---------------- interpreter/value_uint64.go | 74 +++++++++++++++---------------- interpreter/value_uint8.go | 74 +++++++++++++++---------------- interpreter/value_word128.go | 50 ++++++++++----------- interpreter/value_word16.go | 50 ++++++++++----------- interpreter/value_word256.go | 50 ++++++++++----------- interpreter/value_word32.go | 50 ++++++++++----------- interpreter/value_word64.go | 50 ++++++++++----------- interpreter/value_word8.go | 50 ++++++++++----------- 24 files changed, 776 insertions(+), 770 deletions(-) diff --git a/interpreter/interface.go b/interpreter/interface.go index d31593fd66..0e112f2b6e 100644 --- a/interpreter/interface.go +++ b/interpreter/interface.go @@ -60,3 +60,9 @@ type ComparisonContext interface { } var _ ComparisonContext = &Interpreter{} + +type ArithmeticContext interface { + StaticTypeGetter +} + +var _ ArithmeticContext = &Interpreter{} diff --git a/interpreter/value_fix64.go b/interpreter/value_fix64.go index cfd8d7bbf0..af0c6846bc 100644 --- a/interpreter/value_fix64.go +++ b/interpreter/value_fix64.go @@ -123,7 +123,7 @@ func (v Fix64Value) ToInt(_ LocationRange) int { return int(v / sema.Fix64Factor) } -func (v Fix64Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { +func (v Fix64Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt64 { panic(OverflowError{ @@ -135,16 +135,16 @@ func (v Fix64Value) Negate(interpreter *Interpreter, locationRange LocationRange return int64(-v) } - return NewFix64Value(interpreter, valueGetter) + return NewFix64Value(context, valueGetter) } -func (v Fix64Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -153,16 +153,16 @@ func (v Fix64Value) Plus(interpreter *Interpreter, other NumberValue, locationRa return safeAddInt64(int64(v), int64(o), locationRange) } - return NewFix64Value(interpreter, valueGetter) + return NewFix64Value(context, valueGetter) } -func (v Fix64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -177,16 +177,16 @@ func (v Fix64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, return int64(v + o) } - return NewFix64Value(interpreter, valueGetter) + return NewFix64Value(context, valueGetter) } -func (v Fix64Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -206,16 +206,16 @@ func (v Fix64Value) Minus(interpreter *Interpreter, other NumberValue, locationR return int64(v - o) } - return NewFix64Value(interpreter, valueGetter) + return NewFix64Value(context, valueGetter) } -func (v Fix64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -230,19 +230,19 @@ func (v Fix64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, return int64(v - o) } - return NewFix64Value(interpreter, valueGetter) + return NewFix64Value(context, valueGetter) } var minInt64Big = big.NewInt(math.MinInt64) var maxInt64Big = big.NewInt(math.MaxInt64) -func (v Fix64Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -267,16 +267,16 @@ func (v Fix64Value) Mul(interpreter *Interpreter, other NumberValue, locationRan return result.Int64() } - return NewFix64Value(interpreter, valueGetter) + return NewFix64Value(context, valueGetter) } -func (v Fix64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -297,16 +297,16 @@ func (v Fix64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, l return result.Int64() } - return NewFix64Value(interpreter, valueGetter) + return NewFix64Value(context, valueGetter) } -func (v Fix64Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -331,16 +331,16 @@ func (v Fix64Value) Div(interpreter *Interpreter, other NumberValue, locationRan return result.Int64() } - return NewFix64Value(interpreter, valueGetter) + return NewFix64Value(context, valueGetter) } -func (v Fix64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -361,41 +361,41 @@ func (v Fix64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l return result.Int64() } - return NewFix64Value(interpreter, valueGetter) + return NewFix64Value(context, valueGetter) } -func (v Fix64Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } // v - int(v/o) * o - quotient, ok := v.Div(interpreter, o, locationRange).(Fix64Value) + quotient, ok := v.Div(context, o, locationRange).(Fix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } truncatedQuotient := NewFix64Value( - interpreter, + context, func() int64 { return (int64(quotient) / sema.Fix64Factor) * sema.Fix64Factor }, ) return v.Minus( - interpreter, - truncatedQuotient.Mul(interpreter, o, locationRange), + context, + truncatedQuotient.Mul(context, o, locationRange), locationRange, ) } diff --git a/interpreter/value_int.go b/interpreter/value_int.go index ddf2c5d6db..0a903387dc 100644 --- a/interpreter/value_int.go +++ b/interpreter/value_int.go @@ -171,9 +171,9 @@ func (v IntValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ Lo return v.String() } -func (v IntValue) Negate(interpreter *Interpreter, _ LocationRange) NumberValue { +func (v IntValue) Negate(context ArithmeticContext, _ LocationRange) NumberValue { return NewIntValueFromBigInt( - interpreter, + context, common.NewNegateBigIntMemoryUsage(v.BigInt), func() *big.Int { return new(big.Int).Neg(v.BigInt) @@ -181,19 +181,19 @@ func (v IntValue) Negate(interpreter *Interpreter, _ LocationRange) NumberValue ) } -func (v IntValue) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewIntValueFromBigInt( - interpreter, + context, common.NewPlusBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -202,35 +202,35 @@ func (v IntValue) Plus(interpreter *Interpreter, other NumberValue, locationRang ) } -func (v IntValue) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Plus(interpreter, other, locationRange) + return v.Plus(context, other, locationRange) } -func (v IntValue) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewIntValueFromBigInt( - interpreter, + context, common.NewMinusBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -239,35 +239,35 @@ func (v IntValue) Minus(interpreter *Interpreter, other NumberValue, locationRan ) } -func (v IntValue) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Minus(interpreter, other, locationRange) + return v.Minus(context, other, locationRange) } -func (v IntValue) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewIntValueFromBigInt( - interpreter, + context, common.NewModBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -282,19 +282,19 @@ func (v IntValue) Mod(interpreter *Interpreter, other NumberValue, locationRange ) } -func (v IntValue) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewIntValueFromBigInt( - interpreter, + context, common.NewMulBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -303,35 +303,35 @@ func (v IntValue) Mul(interpreter *Interpreter, other NumberValue, locationRange ) } -func (v IntValue) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Mul(interpreter, other, locationRange) + return v.Mul(context, other, locationRange) } -func (v IntValue) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewIntValueFromBigInt( - interpreter, + context, common.NewDivBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -346,20 +346,20 @@ func (v IntValue) Div(interpreter *Interpreter, other NumberValue, locationRange ) } -func (v IntValue) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Div(interpreter, other, locationRange) + return v.Div(context, other, locationRange) } func (v IntValue) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_int128.go b/interpreter/value_int128.go index 8e6fdcf577..96ed47ffe8 100644 --- a/interpreter/value_int128.go +++ b/interpreter/value_int128.go @@ -126,7 +126,7 @@ func (v Int128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ return v.String() } -func (v Int128Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { +func (v Int128Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C // if v == Int128TypeMinIntBig { // ... @@ -141,16 +141,16 @@ func (v Int128Value) Negate(interpreter *Interpreter, locationRange LocationRang return new(big.Int).Neg(v.BigInt) } - return NewInt128ValueFromBigInt(interpreter, valueGetter) + return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -183,16 +183,16 @@ func (v Int128Value) Plus(interpreter *Interpreter, other NumberValue, locationR return res } - return NewInt128ValueFromBigInt(interpreter, valueGetter) + return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -221,16 +221,16 @@ func (v Int128Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, return res } - return NewInt128ValueFromBigInt(interpreter, valueGetter) + return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -263,16 +263,16 @@ func (v Int128Value) Minus(interpreter *Interpreter, other NumberValue, location return res } - return NewInt128ValueFromBigInt(interpreter, valueGetter) + return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -301,16 +301,16 @@ func (v Int128Value) SaturatingMinus(interpreter *Interpreter, other NumberValue return res } - return NewInt128ValueFromBigInt(interpreter, valueGetter) + return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -328,16 +328,16 @@ func (v Int128Value) Mod(interpreter *Interpreter, other NumberValue, locationRa return res } - return NewInt128ValueFromBigInt(interpreter, valueGetter) + return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -358,16 +358,16 @@ func (v Int128Value) Mul(interpreter *Interpreter, other NumberValue, locationRa return res } - return NewInt128ValueFromBigInt(interpreter, valueGetter) + return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -384,16 +384,16 @@ func (v Int128Value) SaturatingMul(interpreter *Interpreter, other NumberValue, return res } - return NewInt128ValueFromBigInt(interpreter, valueGetter) + return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -422,16 +422,16 @@ func (v Int128Value) Div(interpreter *Interpreter, other NumberValue, locationRa return res } - return NewInt128ValueFromBigInt(interpreter, valueGetter) + return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -458,7 +458,7 @@ func (v Int128Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, return res } - return NewInt128ValueFromBigInt(interpreter, valueGetter) + return NewInt128ValueFromBigInt(context, valueGetter) } func (v Int128Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_int16.go b/interpreter/value_int16.go index 2d1c7028d2..aa15c5e670 100644 --- a/interpreter/value_int16.go +++ b/interpreter/value_int16.go @@ -99,7 +99,7 @@ func (v Int16Value) ToInt(_ LocationRange) int { return int(v) } -func (v Int16Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { +func (v Int16Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt16 { panic(OverflowError{ @@ -111,16 +111,16 @@ func (v Int16Value) Negate(interpreter *Interpreter, locationRange LocationRange return int16(-v) } - return NewInt16Value(interpreter, valueGetter) + return NewInt16Value(context, valueGetter) } -func (v Int16Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -140,16 +140,16 @@ func (v Int16Value) Plus(interpreter *Interpreter, other NumberValue, locationRa return int16(v + o) } - return NewInt16Value(interpreter, valueGetter) + return NewInt16Value(context, valueGetter) } -func (v Int16Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -164,16 +164,16 @@ func (v Int16Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, return int16(v + o) } - return NewInt16Value(interpreter, valueGetter) + return NewInt16Value(context, valueGetter) } -func (v Int16Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -193,16 +193,16 @@ func (v Int16Value) Minus(interpreter *Interpreter, other NumberValue, locationR return int16(v - o) } - return NewInt16Value(interpreter, valueGetter) + return NewInt16Value(context, valueGetter) } -func (v Int16Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -217,16 +217,16 @@ func (v Int16Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, return int16(v - o) } - return NewInt16Value(interpreter, valueGetter) + return NewInt16Value(context, valueGetter) } -func (v Int16Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -242,16 +242,16 @@ func (v Int16Value) Mod(interpreter *Interpreter, other NumberValue, locationRan return int16(v % o) } - return NewInt16Value(interpreter, valueGetter) + return NewInt16Value(context, valueGetter) } -func (v Int16Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -295,16 +295,16 @@ func (v Int16Value) Mul(interpreter *Interpreter, other NumberValue, locationRan return int16(v * o) } - return NewInt16Value(interpreter, valueGetter) + return NewInt16Value(context, valueGetter) } -func (v Int16Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -339,16 +339,16 @@ func (v Int16Value) SaturatingMul(interpreter *Interpreter, other NumberValue, l return int16(v * o) } - return NewInt16Value(interpreter, valueGetter) + return NewInt16Value(context, valueGetter) } -func (v Int16Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -369,16 +369,16 @@ func (v Int16Value) Div(interpreter *Interpreter, other NumberValue, locationRan return int16(v / o) } - return NewInt16Value(interpreter, valueGetter) + return NewInt16Value(context, valueGetter) } -func (v Int16Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -396,7 +396,7 @@ func (v Int16Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l return int16(v / o) } - return NewInt16Value(interpreter, valueGetter) + return NewInt16Value(context, valueGetter) } func (v Int16Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_int256.go b/interpreter/value_int256.go index d257629b91..2943a082b6 100644 --- a/interpreter/value_int256.go +++ b/interpreter/value_int256.go @@ -126,7 +126,7 @@ func (v Int256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ return v.String() } -func (v Int256Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { +func (v Int256Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C // if v == Int256TypeMinIntBig { // ... @@ -141,16 +141,16 @@ func (v Int256Value) Negate(interpreter *Interpreter, locationRange LocationRang return new(big.Int).Neg(v.BigInt) } - return NewInt256ValueFromBigInt(interpreter, valueGetter) + return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -183,16 +183,16 @@ func (v Int256Value) Plus(interpreter *Interpreter, other NumberValue, locationR return res } - return NewInt256ValueFromBigInt(interpreter, valueGetter) + return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -221,16 +221,16 @@ func (v Int256Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, return res } - return NewInt256ValueFromBigInt(interpreter, valueGetter) + return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -263,16 +263,16 @@ func (v Int256Value) Minus(interpreter *Interpreter, other NumberValue, location return res } - return NewInt256ValueFromBigInt(interpreter, valueGetter) + return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -301,16 +301,16 @@ func (v Int256Value) SaturatingMinus(interpreter *Interpreter, other NumberValue return res } - return NewInt256ValueFromBigInt(interpreter, valueGetter) + return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -328,16 +328,16 @@ func (v Int256Value) Mod(interpreter *Interpreter, other NumberValue, locationRa return res } - return NewInt256ValueFromBigInt(interpreter, valueGetter) + return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -358,16 +358,16 @@ func (v Int256Value) Mul(interpreter *Interpreter, other NumberValue, locationRa return res } - return NewInt256ValueFromBigInt(interpreter, valueGetter) + return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -384,16 +384,16 @@ func (v Int256Value) SaturatingMul(interpreter *Interpreter, other NumberValue, return res } - return NewInt256ValueFromBigInt(interpreter, valueGetter) + return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -421,16 +421,16 @@ func (v Int256Value) Div(interpreter *Interpreter, other NumberValue, locationRa return res } - return NewInt256ValueFromBigInt(interpreter, valueGetter) + return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -456,7 +456,7 @@ func (v Int256Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, return res } - return NewInt256ValueFromBigInt(interpreter, valueGetter) + return NewInt256ValueFromBigInt(context, valueGetter) } func (v Int256Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_int32.go b/interpreter/value_int32.go index 14c79848c9..b7554a74e3 100644 --- a/interpreter/value_int32.go +++ b/interpreter/value_int32.go @@ -99,7 +99,7 @@ func (v Int32Value) ToInt(_ LocationRange) int { return int(v) } -func (v Int32Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { +func (v Int32Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt32 { panic(OverflowError{ @@ -111,16 +111,16 @@ func (v Int32Value) Negate(interpreter *Interpreter, locationRange LocationRange return int32(-v) } - return NewInt32Value(interpreter, valueGetter) + return NewInt32Value(context, valueGetter) } -func (v Int32Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -140,16 +140,16 @@ func (v Int32Value) Plus(interpreter *Interpreter, other NumberValue, locationRa return int32(v + o) } - return NewInt32Value(interpreter, valueGetter) + return NewInt32Value(context, valueGetter) } -func (v Int32Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -164,16 +164,16 @@ func (v Int32Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, return int32(v + o) } - return NewInt32Value(interpreter, valueGetter) + return NewInt32Value(context, valueGetter) } -func (v Int32Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -193,16 +193,16 @@ func (v Int32Value) Minus(interpreter *Interpreter, other NumberValue, locationR return int32(v - o) } - return NewInt32Value(interpreter, valueGetter) + return NewInt32Value(context, valueGetter) } -func (v Int32Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -217,16 +217,16 @@ func (v Int32Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, return int32(v - o) } - return NewInt32Value(interpreter, valueGetter) + return NewInt32Value(context, valueGetter) } -func (v Int32Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -242,16 +242,16 @@ func (v Int32Value) Mod(interpreter *Interpreter, other NumberValue, locationRan return int32(v % o) } - return NewInt32Value(interpreter, valueGetter) + return NewInt32Value(context, valueGetter) } -func (v Int32Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -295,16 +295,16 @@ func (v Int32Value) Mul(interpreter *Interpreter, other NumberValue, locationRan return int32(v * o) } - return NewInt32Value(interpreter, valueGetter) + return NewInt32Value(context, valueGetter) } -func (v Int32Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -339,16 +339,16 @@ func (v Int32Value) SaturatingMul(interpreter *Interpreter, other NumberValue, l return int32(v * o) } - return NewInt32Value(interpreter, valueGetter) + return NewInt32Value(context, valueGetter) } -func (v Int32Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -369,16 +369,16 @@ func (v Int32Value) Div(interpreter *Interpreter, other NumberValue, locationRan return int32(v / o) } - return NewInt32Value(interpreter, valueGetter) + return NewInt32Value(context, valueGetter) } -func (v Int32Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -397,7 +397,7 @@ func (v Int32Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l return int32(v / o) } - return NewInt32Value(interpreter, valueGetter) + return NewInt32Value(context, valueGetter) } func (v Int32Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_int64.go b/interpreter/value_int64.go index 86863b8853..1e855ebedc 100644 --- a/interpreter/value_int64.go +++ b/interpreter/value_int64.go @@ -96,7 +96,7 @@ func (v Int64Value) ToInt(_ LocationRange) int { return int(v) } -func (v Int64Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { +func (v Int64Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt64 { panic(OverflowError{ @@ -108,7 +108,7 @@ func (v Int64Value) Negate(interpreter *Interpreter, locationRange LocationRange return int64(-v) } - return NewInt64Value(interpreter, valueGetter) + return NewInt64Value(context, valueGetter) } func safeAddInt64(a, b int64, locationRange LocationRange) int64 { @@ -125,13 +125,13 @@ func safeAddInt64(a, b int64, locationRange LocationRange) int64 { return a + b } -func (v Int64Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -140,16 +140,16 @@ func (v Int64Value) Plus(interpreter *Interpreter, other NumberValue, locationRa return safeAddInt64(int64(v), int64(o), locationRange) } - return NewInt64Value(interpreter, valueGetter) + return NewInt64Value(context, valueGetter) } -func (v Int64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -164,16 +164,16 @@ func (v Int64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, return int64(v + o) } - return NewInt64Value(interpreter, valueGetter) + return NewInt64Value(context, valueGetter) } -func (v Int64Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -193,16 +193,16 @@ func (v Int64Value) Minus(interpreter *Interpreter, other NumberValue, locationR return int64(v - o) } - return NewInt64Value(interpreter, valueGetter) + return NewInt64Value(context, valueGetter) } -func (v Int64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -217,16 +217,16 @@ func (v Int64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, return int64(v - o) } - return NewInt64Value(interpreter, valueGetter) + return NewInt64Value(context, valueGetter) } -func (v Int64Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -242,16 +242,16 @@ func (v Int64Value) Mod(interpreter *Interpreter, other NumberValue, locationRan return int64(v % o) } - return NewInt64Value(interpreter, valueGetter) + return NewInt64Value(context, valueGetter) } -func (v Int64Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -295,16 +295,16 @@ func (v Int64Value) Mul(interpreter *Interpreter, other NumberValue, locationRan return int64(v * o) } - return NewInt64Value(interpreter, valueGetter) + return NewInt64Value(context, valueGetter) } -func (v Int64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -339,16 +339,16 @@ func (v Int64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, l return int64(v * o) } - return NewInt64Value(interpreter, valueGetter) + return NewInt64Value(context, valueGetter) } -func (v Int64Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -369,16 +369,16 @@ func (v Int64Value) Div(interpreter *Interpreter, other NumberValue, locationRan return int64(v / o) } - return NewInt64Value(interpreter, valueGetter) + return NewInt64Value(context, valueGetter) } -func (v Int64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -396,7 +396,7 @@ func (v Int64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l return int64(v / o) } - return NewInt64Value(interpreter, valueGetter) + return NewInt64Value(context, valueGetter) } func (v Int64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_int8.go b/interpreter/value_int8.go index 1411687883..a5acdf7842 100644 --- a/interpreter/value_int8.go +++ b/interpreter/value_int8.go @@ -97,7 +97,7 @@ func (v Int8Value) ToInt(_ LocationRange) int { return int(v) } -func (v Int8Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { +func (v Int8Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt8 { panic(OverflowError{ @@ -109,16 +109,16 @@ func (v Int8Value) Negate(interpreter *Interpreter, locationRange LocationRange) return int8(-v) } - return NewInt8Value(interpreter, valueGetter) + return NewInt8Value(context, valueGetter) } -func (v Int8Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -138,16 +138,16 @@ func (v Int8Value) Plus(interpreter *Interpreter, other NumberValue, locationRan return int8(v + o) } - return NewInt8Value(interpreter, valueGetter) + return NewInt8Value(context, valueGetter) } -func (v Int8Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -162,16 +162,16 @@ func (v Int8Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, l return int8(v + o) } - return NewInt8Value(interpreter, valueGetter) + return NewInt8Value(context, valueGetter) } -func (v Int8Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -191,16 +191,16 @@ func (v Int8Value) Minus(interpreter *Interpreter, other NumberValue, locationRa return int8(v - o) } - return NewInt8Value(interpreter, valueGetter) + return NewInt8Value(context, valueGetter) } -func (v Int8Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -215,16 +215,16 @@ func (v Int8Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, return int8(v - o) } - return NewInt8Value(interpreter, valueGetter) + return NewInt8Value(context, valueGetter) } -func (v Int8Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -240,16 +240,16 @@ func (v Int8Value) Mod(interpreter *Interpreter, other NumberValue, locationRang return int8(v % o) } - return NewInt8Value(interpreter, valueGetter) + return NewInt8Value(context, valueGetter) } -func (v Int8Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -293,16 +293,16 @@ func (v Int8Value) Mul(interpreter *Interpreter, other NumberValue, locationRang return int8(v * o) } - return NewInt8Value(interpreter, valueGetter) + return NewInt8Value(context, valueGetter) } -func (v Int8Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -338,16 +338,16 @@ func (v Int8Value) SaturatingMul(interpreter *Interpreter, other NumberValue, lo return int8(v * o) } - return NewInt8Value(interpreter, valueGetter) + return NewInt8Value(context, valueGetter) } -func (v Int8Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -368,16 +368,16 @@ func (v Int8Value) Div(interpreter *Interpreter, other NumberValue, locationRang return int8(v / o) } - return NewInt8Value(interpreter, valueGetter) + return NewInt8Value(context, valueGetter) } -func (v Int8Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -395,7 +395,7 @@ func (v Int8Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, lo return int8(v / o) } - return NewInt8Value(interpreter, valueGetter) + return NewInt8Value(context, valueGetter) } func (v Int8Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_number.go b/interpreter/value_number.go index f0374dcf57..25fe93990f 100644 --- a/interpreter/value_number.go +++ b/interpreter/value_number.go @@ -30,16 +30,16 @@ import ( type NumberValue interface { ComparableValue ToInt(locationRange LocationRange) int - Negate(*Interpreter, LocationRange) NumberValue - Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue - SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue - Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue - SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue - Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue - Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue - SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue - Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue - SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue + Negate(context ArithmeticContext, locationRange LocationRange) NumberValue + Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue ToBigEndianBytes() []byte } diff --git a/interpreter/value_ufix64.go b/interpreter/value_ufix64.go index 571257d364..52218ee1b6 100644 --- a/interpreter/value_ufix64.go +++ b/interpreter/value_ufix64.go @@ -116,17 +116,17 @@ func (v UFix64Value) ToInt(_ LocationRange) int { return int(v / sema.Fix64Factor) } -func (v UFix64Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v UFix64Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UFix64Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -135,16 +135,16 @@ func (v UFix64Value) Plus(interpreter *Interpreter, other NumberValue, locationR return safeAddUint64(uint64(v), uint64(o), locationRange) } - return NewUFix64Value(interpreter, valueGetter) + return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -158,16 +158,16 @@ func (v UFix64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, return uint64(sum) } - return NewUFix64Value(interpreter, valueGetter) + return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -184,16 +184,16 @@ func (v UFix64Value) Minus(interpreter *Interpreter, other NumberValue, location return uint64(diff) } - return NewUFix64Value(interpreter, valueGetter) + return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -208,16 +208,16 @@ func (v UFix64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue return uint64(diff) } - return NewUFix64Value(interpreter, valueGetter) + return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -238,16 +238,16 @@ func (v UFix64Value) Mul(interpreter *Interpreter, other NumberValue, locationRa return result.Uint64() } - return NewUFix64Value(interpreter, valueGetter) + return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -266,16 +266,16 @@ func (v UFix64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, return result.Uint64() } - return NewUFix64Value(interpreter, valueGetter) + return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -290,57 +290,57 @@ func (v UFix64Value) Div(interpreter *Interpreter, other NumberValue, locationRa return result.Uint64() } - return NewUFix64Value(interpreter, valueGetter) + return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Div(interpreter, other, locationRange) + return v.Div(context, other, locationRange) } -func (v UFix64Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } // v - int(v/o) * o - quotient, ok := v.Div(interpreter, o, locationRange).(UFix64Value) + quotient, ok := v.Div(context, o, locationRange).(UFix64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } truncatedQuotient := NewUFix64Value( - interpreter, + context, func() uint64 { return (uint64(quotient) / sema.Fix64Factor) * sema.Fix64Factor }, ) return v.Minus( - interpreter, - truncatedQuotient.Mul(interpreter, o, locationRange), + context, + truncatedQuotient.Mul(context, o, locationRange), locationRange, ) } diff --git a/interpreter/value_uint.go b/interpreter/value_uint.go index e1a9422c09..f85dc6bcae 100644 --- a/interpreter/value_uint.go +++ b/interpreter/value_uint.go @@ -168,23 +168,23 @@ func (v UIntValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ L return v.String() } -func (v UIntValue) Negate(*Interpreter, LocationRange) NumberValue { +func (v UIntValue) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UIntValue) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUIntValueFromBigInt( - interpreter, + context, common.NewPlusBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -193,35 +193,35 @@ func (v UIntValue) Plus(interpreter *Interpreter, other NumberValue, locationRan ) } -func (v UIntValue) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Plus(interpreter, other, locationRange) + return v.Plus(context, other, locationRange) } -func (v UIntValue) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUIntValueFromBigInt( - interpreter, + context, common.NewMinusBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -237,19 +237,19 @@ func (v UIntValue) Minus(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UIntValue) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUIntValueFromBigInt( - interpreter, + context, common.NewMinusBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -263,19 +263,19 @@ func (v UIntValue) SaturatingMinus(interpreter *Interpreter, other NumberValue, ) } -func (v UIntValue) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUIntValueFromBigInt( - interpreter, + context, common.NewModBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -291,19 +291,19 @@ func (v UIntValue) Mod(interpreter *Interpreter, other NumberValue, locationRang ) } -func (v UIntValue) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUIntValueFromBigInt( - interpreter, + context, common.NewMulBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -312,35 +312,35 @@ func (v UIntValue) Mul(interpreter *Interpreter, other NumberValue, locationRang ) } -func (v UIntValue) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Mul(interpreter, other, locationRange) + return v.Mul(context, other, locationRange) } -func (v UIntValue) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUIntValueFromBigInt( - interpreter, + context, common.NewDivBigIntMemoryUsage(v.BigInt, o.BigInt), func() *big.Int { res := new(big.Int) @@ -355,20 +355,20 @@ func (v UIntValue) Div(interpreter *Interpreter, other NumberValue, locationRang ) } -func (v UIntValue) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Div(interpreter, other, locationRange) + return v.Div(context, other, locationRange) } func (v UIntValue) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_uint128.go b/interpreter/value_uint128.go index 7ac30e7aae..9fd90ad772 100644 --- a/interpreter/value_uint128.go +++ b/interpreter/value_uint128.go @@ -126,23 +126,23 @@ func (v UInt128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, return v.String() } -func (v UInt128Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v UInt128Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UInt128Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt128ValueFromBigInt( - interpreter, + context, func() *big.Int { sum := new(big.Int) sum.Add(v.BigInt, o.BigInt) @@ -166,19 +166,19 @@ func (v UInt128Value) Plus(interpreter *Interpreter, other NumberValue, location ) } -func (v UInt128Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt128ValueFromBigInt( - interpreter, + context, func() *big.Int { sum := new(big.Int) sum.Add(v.BigInt, o.BigInt) @@ -200,19 +200,19 @@ func (v UInt128Value) SaturatingPlus(interpreter *Interpreter, other NumberValue ) } -func (v UInt128Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt128ValueFromBigInt( - interpreter, + context, func() *big.Int { diff := new(big.Int) diff.Sub(v.BigInt, o.BigInt) @@ -236,19 +236,19 @@ func (v UInt128Value) Minus(interpreter *Interpreter, other NumberValue, locatio ) } -func (v UInt128Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt128ValueFromBigInt( - interpreter, + context, func() *big.Int { diff := new(big.Int) diff.Sub(v.BigInt, o.BigInt) @@ -270,19 +270,19 @@ func (v UInt128Value) SaturatingMinus(interpreter *Interpreter, other NumberValu ) } -func (v UInt128Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt128ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { @@ -295,19 +295,19 @@ func (v UInt128Value) Mod(interpreter *Interpreter, other NumberValue, locationR ) } -func (v UInt128Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt128ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) res.Mul(v.BigInt, o.BigInt) @@ -321,19 +321,19 @@ func (v UInt128Value) Mul(interpreter *Interpreter, other NumberValue, locationR ) } -func (v UInt128Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt128ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) res.Mul(v.BigInt, o.BigInt) @@ -345,19 +345,19 @@ func (v UInt128Value) SaturatingMul(interpreter *Interpreter, other NumberValue, ) } -func (v UInt128Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt128ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { @@ -371,20 +371,20 @@ func (v UInt128Value) Div(interpreter *Interpreter, other NumberValue, locationR } -func (v UInt128Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Div(interpreter, other, locationRange) + return v.Div(context, other, locationRange) } func (v UInt128Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_uint16.go b/interpreter/value_uint16.go index 90385be62c..1ff066c8c0 100644 --- a/interpreter/value_uint16.go +++ b/interpreter/value_uint16.go @@ -96,23 +96,23 @@ func (v UInt16Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ func (v UInt16Value) ToInt(_ LocationRange) int { return int(v) } -func (v UInt16Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v UInt16Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UInt16Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt16Value( - interpreter, + context, func() uint16 { sum := v + o // INT30-C @@ -126,19 +126,19 @@ func (v UInt16Value) Plus(interpreter *Interpreter, other NumberValue, locationR ) } -func (v UInt16Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt16Value( - interpreter, + context, func() uint16 { sum := v + o // INT30-C @@ -150,19 +150,19 @@ func (v UInt16Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, ) } -func (v UInt16Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt16Value( - interpreter, + context, func() uint16 { diff := v - o // INT30-C @@ -176,19 +176,19 @@ func (v UInt16Value) Minus(interpreter *Interpreter, other NumberValue, location ) } -func (v UInt16Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt16Value( - interpreter, + context, func() uint16 { diff := v - o // INT30-C @@ -200,19 +200,19 @@ func (v UInt16Value) SaturatingMinus(interpreter *Interpreter, other NumberValue ) } -func (v UInt16Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt16Value( - interpreter, + context, func() uint16 { if o == 0 { panic(DivisionByZeroError{ @@ -224,19 +224,19 @@ func (v UInt16Value) Mod(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UInt16Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt16Value( - interpreter, + context, func() uint16 { // INT30-C if (v > 0) && (o > 0) && (v > (math.MaxUint16 / o)) { @@ -249,19 +249,19 @@ func (v UInt16Value) Mul(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UInt16Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt16Value( - interpreter, + context, func() uint16 { // INT30-C if (v > 0) && (o > 0) && (v > (math.MaxUint16 / o)) { @@ -272,19 +272,19 @@ func (v UInt16Value) SaturatingMul(interpreter *Interpreter, other NumberValue, ) } -func (v UInt16Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt16Value( - interpreter, + context, func() uint16 { if o == 0 { panic(DivisionByZeroError{ @@ -296,20 +296,20 @@ func (v UInt16Value) Div(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UInt16Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Div(interpreter, other, locationRange) + return v.Div(context, other, locationRange) } func (v UInt16Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_uint256.go b/interpreter/value_uint256.go index a1355e8465..0643fc1787 100644 --- a/interpreter/value_uint256.go +++ b/interpreter/value_uint256.go @@ -127,23 +127,23 @@ func (v UInt256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, return v.String() } -func (v UInt256Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v UInt256Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UInt256Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt256ValueFromBigInt( - interpreter, + context, func() *big.Int { sum := new(big.Int) sum.Add(v.BigInt, o.BigInt) @@ -168,19 +168,19 @@ func (v UInt256Value) Plus(interpreter *Interpreter, other NumberValue, location } -func (v UInt256Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt256ValueFromBigInt( - interpreter, + context, func() *big.Int { sum := new(big.Int) sum.Add(v.BigInt, o.BigInt) @@ -202,19 +202,19 @@ func (v UInt256Value) SaturatingPlus(interpreter *Interpreter, other NumberValue ) } -func (v UInt256Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt256ValueFromBigInt( - interpreter, + context, func() *big.Int { diff := new(big.Int) diff.Sub(v.BigInt, o.BigInt) @@ -238,19 +238,19 @@ func (v UInt256Value) Minus(interpreter *Interpreter, other NumberValue, locatio ) } -func (v UInt256Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt256ValueFromBigInt( - interpreter, + context, func() *big.Int { diff := new(big.Int) diff.Sub(v.BigInt, o.BigInt) @@ -273,19 +273,19 @@ func (v UInt256Value) SaturatingMinus(interpreter *Interpreter, other NumberValu } -func (v UInt256Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt256ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { @@ -298,19 +298,19 @@ func (v UInt256Value) Mod(interpreter *Interpreter, other NumberValue, locationR ) } -func (v UInt256Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt256ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) res.Mul(v.BigInt, o.BigInt) @@ -324,19 +324,19 @@ func (v UInt256Value) Mul(interpreter *Interpreter, other NumberValue, locationR ) } -func (v UInt256Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt256ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) res.Mul(v.BigInt, o.BigInt) @@ -348,19 +348,19 @@ func (v UInt256Value) SaturatingMul(interpreter *Interpreter, other NumberValue, ) } -func (v UInt256Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt256ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { @@ -373,20 +373,20 @@ func (v UInt256Value) Div(interpreter *Interpreter, other NumberValue, locationR ) } -func (v UInt256Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Div(interpreter, other, locationRange) + return v.Div(context, other, locationRange) } func (v UInt256Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_uint32.go b/interpreter/value_uint32.go index 88f0b82e61..8923b16548 100644 --- a/interpreter/value_uint32.go +++ b/interpreter/value_uint32.go @@ -97,23 +97,23 @@ func (v UInt32Value) ToInt(_ LocationRange) int { return int(v) } -func (v UInt32Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v UInt32Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UInt32Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt32Value( - interpreter, + context, func() uint32 { sum := v + o // INT30-C @@ -127,19 +127,19 @@ func (v UInt32Value) Plus(interpreter *Interpreter, other NumberValue, locationR ) } -func (v UInt32Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt32Value( - interpreter, + context, func() uint32 { sum := v + o // INT30-C @@ -151,19 +151,19 @@ func (v UInt32Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, ) } -func (v UInt32Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt32Value( - interpreter, + context, func() uint32 { diff := v - o // INT30-C @@ -177,19 +177,19 @@ func (v UInt32Value) Minus(interpreter *Interpreter, other NumberValue, location ) } -func (v UInt32Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt32Value( - interpreter, + context, func() uint32 { diff := v - o // INT30-C @@ -201,19 +201,19 @@ func (v UInt32Value) SaturatingMinus(interpreter *Interpreter, other NumberValue ) } -func (v UInt32Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt32Value( - interpreter, + context, func() uint32 { if o == 0 { panic(DivisionByZeroError{ @@ -225,19 +225,19 @@ func (v UInt32Value) Mod(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UInt32Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt32Value( - interpreter, + context, func() uint32 { if (v > 0) && (o > 0) && (v > (math.MaxUint32 / o)) { panic(OverflowError{ @@ -249,19 +249,19 @@ func (v UInt32Value) Mul(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UInt32Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt32Value( - interpreter, + context, func() uint32 { // INT30-C @@ -273,19 +273,19 @@ func (v UInt32Value) SaturatingMul(interpreter *Interpreter, other NumberValue, ) } -func (v UInt32Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt32Value( - interpreter, + context, func() uint32 { if o == 0 { panic(DivisionByZeroError{ @@ -297,20 +297,20 @@ func (v UInt32Value) Div(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UInt32Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Div(interpreter, other, locationRange) + return v.Div(context, other, locationRange) } func (v UInt32Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_uint64.go b/interpreter/value_uint64.go index d1c736bca6..9e34eca4cf 100644 --- a/interpreter/value_uint64.go +++ b/interpreter/value_uint64.go @@ -124,7 +124,7 @@ func (v UInt64Value) ToBigInt(memoryGauge common.MemoryGauge) *big.Int { return new(big.Int).SetUint64(uint64(v)) } -func (v UInt64Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v UInt64Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } @@ -139,38 +139,38 @@ func safeAddUint64(a, b uint64, locationRange LocationRange) uint64 { return sum } -func (v UInt64Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt64Value( - interpreter, + context, func() uint64 { return safeAddUint64(uint64(v), uint64(o), locationRange) }, ) } -func (v UInt64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt64Value( - interpreter, + context, func() uint64 { sum := v + o // INT30-C @@ -182,19 +182,19 @@ func (v UInt64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, ) } -func (v UInt64Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt64Value( - interpreter, + context, func() uint64 { diff := v - o // INT30-C @@ -208,19 +208,19 @@ func (v UInt64Value) Minus(interpreter *Interpreter, other NumberValue, location ) } -func (v UInt64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt64Value( - interpreter, + context, func() uint64 { diff := v - o // INT30-C @@ -232,19 +232,19 @@ func (v UInt64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue ) } -func (v UInt64Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt64Value( - interpreter, + context, func() uint64 { if o == 0 { panic(DivisionByZeroError{ @@ -256,19 +256,19 @@ func (v UInt64Value) Mod(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UInt64Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt64Value( - interpreter, + context, func() uint64 { if (v > 0) && (o > 0) && (v > (math.MaxUint64 / o)) { panic(OverflowError{ @@ -280,19 +280,19 @@ func (v UInt64Value) Mul(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UInt64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt64Value( - interpreter, + context, func() uint64 { // INT30-C if (v > 0) && (o > 0) && (v > (math.MaxUint64 / o)) { @@ -303,19 +303,19 @@ func (v UInt64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, ) } -func (v UInt64Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt64Value( - interpreter, + context, func() uint64 { if o == 0 { panic(DivisionByZeroError{ @@ -327,20 +327,20 @@ func (v UInt64Value) Div(interpreter *Interpreter, other NumberValue, locationRa ) } -func (v UInt64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Div(interpreter, other, locationRange) + return v.Div(context, other, locationRange) } func (v UInt64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_uint8.go b/interpreter/value_uint8.go index a9916b3749..5080df6887 100644 --- a/interpreter/value_uint8.go +++ b/interpreter/value_uint8.go @@ -97,22 +97,22 @@ func (v UInt8Value) ToInt(_ LocationRange) int { return int(v) } -func (v UInt8Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v UInt8Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UInt8Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } - return NewUInt8Value(interpreter, func() uint8 { + return NewUInt8Value(context, func() uint8 { sum := v + o // INT30-C if sum < v { @@ -124,18 +124,18 @@ func (v UInt8Value) Plus(interpreter *Interpreter, other NumberValue, locationRa }) } -func (v UInt8Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } - return NewUInt8Value(interpreter, func() uint8 { + return NewUInt8Value(context, func() uint8 { sum := v + o // INT30-C if sum < v { @@ -145,19 +145,19 @@ func (v UInt8Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, }) } -func (v UInt8Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt8Value( - interpreter, + context, func() uint8 { diff := v - o // INT30-C @@ -171,19 +171,19 @@ func (v UInt8Value) Minus(interpreter *Interpreter, other NumberValue, locationR ) } -func (v UInt8Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt8Value( - interpreter, + context, func() uint8 { diff := v - o // INT30-C @@ -195,19 +195,19 @@ func (v UInt8Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, ) } -func (v UInt8Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt8Value( - interpreter, + context, func() uint8 { if o == 0 { panic(DivisionByZeroError{ @@ -219,19 +219,19 @@ func (v UInt8Value) Mod(interpreter *Interpreter, other NumberValue, locationRan ) } -func (v UInt8Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt8Value( - interpreter, + context, func() uint8 { // INT30-C if (v > 0) && (o > 0) && (v > (math.MaxUint8 / o)) { @@ -244,19 +244,19 @@ func (v UInt8Value) Mul(interpreter *Interpreter, other NumberValue, locationRan ) } -func (v UInt8Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt8Value( - interpreter, + context, func() uint8 { // INT30-C if (v > 0) && (o > 0) && (v > (math.MaxUint8 / o)) { @@ -267,19 +267,19 @@ func (v UInt8Value) SaturatingMul(interpreter *Interpreter, other NumberValue, l ) } -func (v UInt8Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewUInt8Value( - interpreter, + context, func() uint8 { if o == 0 { panic(DivisionByZeroError{ @@ -291,20 +291,20 @@ func (v UInt8Value) Div(interpreter *Interpreter, other NumberValue, locationRan ) } -func (v UInt8Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } }() - return v.Div(interpreter, other, locationRange) + return v.Div(context, other, locationRange) } func (v UInt8Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { diff --git a/interpreter/value_word128.go b/interpreter/value_word128.go index e4e4937fd6..b11482a8d7 100644 --- a/interpreter/value_word128.go +++ b/interpreter/value_word128.go @@ -126,23 +126,23 @@ func (v Word128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, return v.String() } -func (v Word128Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v Word128Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word128Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewWord128ValueFromBigInt( - interpreter, + context, func() *big.Int { sum := new(big.Int) sum.Add(v.BigInt, o.BigInt) @@ -168,23 +168,23 @@ func (v Word128Value) Plus(interpreter *Interpreter, other NumberValue, location ) } -func (v Word128Value) SaturatingPlus(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { +func (v Word128Value) SaturatingPlus(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word128Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewWord128ValueFromBigInt( - interpreter, + context, func() *big.Int { diff := new(big.Int) diff.Sub(v.BigInt, o.BigInt) @@ -210,23 +210,23 @@ func (v Word128Value) Minus(interpreter *Interpreter, other NumberValue, locatio ) } -func (v Word128Value) SaturatingMinus(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { +func (v Word128Value) SaturatingMinus(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word128Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewWord128ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { @@ -239,19 +239,19 @@ func (v Word128Value) Mod(interpreter *Interpreter, other NumberValue, locationR ) } -func (v Word128Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewWord128ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) res.Mul(v.BigInt, o.BigInt) @@ -263,23 +263,23 @@ func (v Word128Value) Mul(interpreter *Interpreter, other NumberValue, locationR ) } -func (v Word128Value) SaturatingMul(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { +func (v Word128Value) SaturatingMul(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word128Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewWord128ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { @@ -293,7 +293,7 @@ func (v Word128Value) Div(interpreter *Interpreter, other NumberValue, locationR } -func (v Word128Value) SaturatingDiv(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { +func (v Word128Value) SaturatingDiv(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } diff --git a/interpreter/value_word16.go b/interpreter/value_word16.go index 78b4e640e4..d4e14009a5 100644 --- a/interpreter/value_word16.go +++ b/interpreter/value_word16.go @@ -97,17 +97,17 @@ func (v Word16Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ func (v Word16Value) ToInt(_ LocationRange) int { return int(v) } -func (v Word16Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v Word16Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word16Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word16Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -116,20 +116,20 @@ func (v Word16Value) Plus(interpreter *Interpreter, other NumberValue, locationR return uint16(v + o) } - return NewWord16Value(interpreter, valueGetter) + return NewWord16Value(context, valueGetter) } -func (v Word16Value) SaturatingPlus(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word16Value) SaturatingPlus(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word16Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word16Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -138,20 +138,20 @@ func (v Word16Value) Minus(interpreter *Interpreter, other NumberValue, location return uint16(v - o) } - return NewWord16Value(interpreter, valueGetter) + return NewWord16Value(context, valueGetter) } -func (v Word16Value) SaturatingMinus(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word16Value) SaturatingMinus(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word16Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word16Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -166,16 +166,16 @@ func (v Word16Value) Mod(interpreter *Interpreter, other NumberValue, locationRa return uint16(v % o) } - return NewWord16Value(interpreter, valueGetter) + return NewWord16Value(context, valueGetter) } -func (v Word16Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word16Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -184,20 +184,20 @@ func (v Word16Value) Mul(interpreter *Interpreter, other NumberValue, locationRa return uint16(v * o) } - return NewWord16Value(interpreter, valueGetter) + return NewWord16Value(context, valueGetter) } -func (v Word16Value) SaturatingMul(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word16Value) SaturatingMul(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word16Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word16Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -212,10 +212,10 @@ func (v Word16Value) Div(interpreter *Interpreter, other NumberValue, locationRa return uint16(v / o) } - return NewWord16Value(interpreter, valueGetter) + return NewWord16Value(context, valueGetter) } -func (v Word16Value) SaturatingDiv(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word16Value) SaturatingDiv(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } diff --git a/interpreter/value_word256.go b/interpreter/value_word256.go index d40ab268c0..4bffb20f30 100644 --- a/interpreter/value_word256.go +++ b/interpreter/value_word256.go @@ -126,23 +126,23 @@ func (v Word256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, return v.String() } -func (v Word256Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v Word256Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word256Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewWord256ValueFromBigInt( - interpreter, + context, func() *big.Int { sum := new(big.Int) sum.Add(v.BigInt, o.BigInt) @@ -168,23 +168,23 @@ func (v Word256Value) Plus(interpreter *Interpreter, other NumberValue, location ) } -func (v Word256Value) SaturatingPlus(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { +func (v Word256Value) SaturatingPlus(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word256Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewWord256ValueFromBigInt( - interpreter, + context, func() *big.Int { diff := new(big.Int) diff.Sub(v.BigInt, o.BigInt) @@ -210,23 +210,23 @@ func (v Word256Value) Minus(interpreter *Interpreter, other NumberValue, locatio ) } -func (v Word256Value) SaturatingMinus(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { +func (v Word256Value) SaturatingMinus(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word256Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewWord256ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { @@ -239,19 +239,19 @@ func (v Word256Value) Mod(interpreter *Interpreter, other NumberValue, locationR ) } -func (v Word256Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewWord256ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) res.Mul(v.BigInt, o.BigInt) @@ -263,23 +263,23 @@ func (v Word256Value) Mul(interpreter *Interpreter, other NumberValue, locationR ) } -func (v Word256Value) SaturatingMul(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { +func (v Word256Value) SaturatingMul(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word256Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } return NewWord256ValueFromBigInt( - interpreter, + context, func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { @@ -293,7 +293,7 @@ func (v Word256Value) Div(interpreter *Interpreter, other NumberValue, locationR } -func (v Word256Value) SaturatingDiv(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { +func (v Word256Value) SaturatingDiv(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } diff --git a/interpreter/value_word32.go b/interpreter/value_word32.go index cd2a6e75d5..805bdabe11 100644 --- a/interpreter/value_word32.go +++ b/interpreter/value_word32.go @@ -98,17 +98,17 @@ func (v Word32Value) ToInt(_ LocationRange) int { return int(v) } -func (v Word32Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v Word32Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word32Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word32Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -117,20 +117,20 @@ func (v Word32Value) Plus(interpreter *Interpreter, other NumberValue, locationR return uint32(v + o) } - return NewWord32Value(interpreter, valueGetter) + return NewWord32Value(context, valueGetter) } -func (v Word32Value) SaturatingPlus(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word32Value) SaturatingPlus(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word32Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word32Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -139,20 +139,20 @@ func (v Word32Value) Minus(interpreter *Interpreter, other NumberValue, location return uint32(v - o) } - return NewWord32Value(interpreter, valueGetter) + return NewWord32Value(context, valueGetter) } -func (v Word32Value) SaturatingMinus(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word32Value) SaturatingMinus(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word32Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word32Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -167,16 +167,16 @@ func (v Word32Value) Mod(interpreter *Interpreter, other NumberValue, locationRa return uint32(v % o) } - return NewWord32Value(interpreter, valueGetter) + return NewWord32Value(context, valueGetter) } -func (v Word32Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word32Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -185,20 +185,20 @@ func (v Word32Value) Mul(interpreter *Interpreter, other NumberValue, locationRa return uint32(v * o) } - return NewWord32Value(interpreter, valueGetter) + return NewWord32Value(context, valueGetter) } -func (v Word32Value) SaturatingMul(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word32Value) SaturatingMul(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word32Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word32Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -213,10 +213,10 @@ func (v Word32Value) Div(interpreter *Interpreter, other NumberValue, locationRa return uint32(v / o) } - return NewWord32Value(interpreter, valueGetter) + return NewWord32Value(context, valueGetter) } -func (v Word32Value) SaturatingDiv(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word32Value) SaturatingDiv(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } diff --git a/interpreter/value_word64.go b/interpreter/value_word64.go index feee5d2efa..0cfbfef2a2 100644 --- a/interpreter/value_word64.go +++ b/interpreter/value_word64.go @@ -126,17 +126,17 @@ func (v Word64Value) ToBigInt(memoryGauge common.MemoryGauge) *big.Int { return new(big.Int).SetUint64(uint64(v)) } -func (v Word64Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v Word64Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word64Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word64Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -145,20 +145,20 @@ func (v Word64Value) Plus(interpreter *Interpreter, other NumberValue, locationR return uint64(v + o) } - return NewWord64Value(interpreter, valueGetter) + return NewWord64Value(context, valueGetter) } -func (v Word64Value) SaturatingPlus(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word64Value) SaturatingPlus(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word64Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word64Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -167,20 +167,20 @@ func (v Word64Value) Minus(interpreter *Interpreter, other NumberValue, location return uint64(v - o) } - return NewWord64Value(interpreter, valueGetter) + return NewWord64Value(context, valueGetter) } -func (v Word64Value) SaturatingMinus(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word64Value) SaturatingMinus(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word64Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word64Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -195,16 +195,16 @@ func (v Word64Value) Mod(interpreter *Interpreter, other NumberValue, locationRa return uint64(v % o) } - return NewWord64Value(interpreter, valueGetter) + return NewWord64Value(context, valueGetter) } -func (v Word64Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word64Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -213,20 +213,20 @@ func (v Word64Value) Mul(interpreter *Interpreter, other NumberValue, locationRa return uint64(v * o) } - return NewWord64Value(interpreter, valueGetter) + return NewWord64Value(context, valueGetter) } -func (v Word64Value) SaturatingMul(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word64Value) SaturatingMul(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word64Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word64Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -241,10 +241,10 @@ func (v Word64Value) Div(interpreter *Interpreter, other NumberValue, locationRa return uint64(v / o) } - return NewWord64Value(interpreter, valueGetter) + return NewWord64Value(context, valueGetter) } -func (v Word64Value) SaturatingDiv(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word64Value) SaturatingDiv(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } diff --git a/interpreter/value_word8.go b/interpreter/value_word8.go index 714e38b86a..354a0e536c 100644 --- a/interpreter/value_word8.go +++ b/interpreter/value_word8.go @@ -97,17 +97,17 @@ func (v Word8Value) ToInt(_ LocationRange) int { return int(v) } -func (v Word8Value) Negate(*Interpreter, LocationRange) NumberValue { +func (v Word8Value) Negate(ArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word8Value) Plus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word8Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -116,20 +116,20 @@ func (v Word8Value) Plus(interpreter *Interpreter, other NumberValue, locationRa return uint8(v + o) } - return NewWord8Value(interpreter, valueGetter) + return NewWord8Value(context, valueGetter) } -func (v Word8Value) SaturatingPlus(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word8Value) SaturatingPlus(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word8Value) Minus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word8Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -138,20 +138,20 @@ func (v Word8Value) Minus(interpreter *Interpreter, other NumberValue, locationR return uint8(v - o) } - return NewWord8Value(interpreter, valueGetter) + return NewWord8Value(context, valueGetter) } -func (v Word8Value) SaturatingMinus(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word8Value) SaturatingMinus(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word8Value) Mod(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word8Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -166,16 +166,16 @@ func (v Word8Value) Mod(interpreter *Interpreter, other NumberValue, locationRan return uint8(v % o) } - return NewWord8Value(interpreter, valueGetter) + return NewWord8Value(context, valueGetter) } -func (v Word8Value) Mul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word8Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -184,20 +184,20 @@ func (v Word8Value) Mul(interpreter *Interpreter, other NumberValue, locationRan return uint8(v * o) } - return NewWord8Value(interpreter, valueGetter) + return NewWord8Value(context, valueGetter) } -func (v Word8Value) SaturatingMul(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word8Value) SaturatingMul(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word8Value) Div(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word8Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + LeftType: v.StaticType(context), + RightType: other.StaticType(context), LocationRange: locationRange, }) } @@ -212,10 +212,10 @@ func (v Word8Value) Div(interpreter *Interpreter, other NumberValue, locationRan return uint8(v / o) } - return NewWord8Value(interpreter, valueGetter) + return NewWord8Value(context, valueGetter) } -func (v Word8Value) SaturatingDiv(*Interpreter, NumberValue, LocationRange) NumberValue { +func (v Word8Value) SaturatingDiv(ArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } From 53d2c2e55f3eda3685a57434957c0b8ccc04eb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 2 Dec 2024 15:50:45 -0800 Subject: [PATCH 5/8] decouple InclusiveRange iterator from interpreter --- interpreter/inclusive_range_iterator.go | 16 +++++++++++----- interpreter/value_range.go | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/interpreter/inclusive_range_iterator.go b/interpreter/inclusive_range_iterator.go index 1912e49bfc..0e6cbe8133 100644 --- a/interpreter/inclusive_range_iterator.go +++ b/interpreter/inclusive_range_iterator.go @@ -19,6 +19,7 @@ package interpreter import ( + "github.com/onflow/cadence/common" "github.com/onflow/cadence/errors" "github.com/onflow/cadence/sema" ) @@ -35,19 +36,24 @@ type InclusiveRangeIterator struct { var _ ValueIterator = &InclusiveRangeIterator{} +type InclusiveRangeIteratorContext interface { + common.MemoryGauge + NumberValueArithmeticContext +} + func NewInclusiveRangeIterator( - interpreter *Interpreter, + context InclusiveRangeIteratorContext, locationRange LocationRange, v *CompositeValue, typ InclusiveRangeStaticType, ) *InclusiveRangeIterator { - startValue := getFieldAsIntegerValue(interpreter, v, sema.InclusiveRangeTypeStartFieldName) + startValue := getFieldAsIntegerValue(context, v, sema.InclusiveRangeTypeStartFieldName) zeroValue := GetSmallIntegerValue(0, typ.ElementType) - endValue := getFieldAsIntegerValue(interpreter, v, sema.InclusiveRangeTypeEndFieldName) + endValue := getFieldAsIntegerValue(context, v, sema.InclusiveRangeTypeEndFieldName) - stepValue := getFieldAsIntegerValue(interpreter, v, sema.InclusiveRangeTypeStepFieldName) - stepNegative := stepValue.Less(interpreter, zeroValue, locationRange) + stepValue := getFieldAsIntegerValue(context, v, sema.InclusiveRangeTypeStepFieldName) + stepNegative := stepValue.Less(context, zeroValue, locationRange) return &InclusiveRangeIterator{ rangeValue: v, diff --git a/interpreter/value_range.go b/interpreter/value_range.go index 4bcb35b10f..5c16e67cc8 100644 --- a/interpreter/value_range.go +++ b/interpreter/value_range.go @@ -224,9 +224,9 @@ func rangeContains( return AsBoolValue(result) } -func getFieldAsIntegerValue(interpreter *Interpreter, rangeValue *CompositeValue, name string) IntegerValue { +func getFieldAsIntegerValue(memoryGauge common.MemoryGauge, rangeValue *CompositeValue, name string) IntegerValue { return convertAndAssertIntegerValue( - rangeValue.GetField(interpreter, name), + rangeValue.GetField(memoryGauge, name), ) } From fbd8634cf17d9b6433e23a7104ca680feb06b3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 2 Dec 2024 15:50:58 -0800 Subject: [PATCH 6/8] improve naming --- interpreter/interface.go | 17 ++-------- interpreter/simplecompositevalue.go | 2 +- interpreter/value.go | 21 ++++++++---- .../value_accountcapabilitycontroller.go | 4 +-- interpreter/value_address.go | 6 ++-- interpreter/value_array.go | 4 +-- interpreter/value_bool.go | 14 ++++---- interpreter/value_capability.go | 6 ++-- interpreter/value_character.go | 14 ++++---- interpreter/value_composite.go | 6 ++-- interpreter/value_dictionary.go | 6 ++-- interpreter/value_ephemeral_reference.go | 8 ++--- interpreter/value_fix64.go | 34 +++++++++---------- interpreter/value_function.go | 12 +++---- interpreter/value_int.go | 34 +++++++++---------- interpreter/value_int128.go | 34 +++++++++---------- interpreter/value_int16.go | 34 +++++++++---------- interpreter/value_int256.go | 34 +++++++++---------- interpreter/value_int32.go | 34 +++++++++---------- interpreter/value_int64.go | 34 +++++++++---------- interpreter/value_int8.go | 34 +++++++++---------- interpreter/value_link.go | 14 ++++---- interpreter/value_nil.go | 8 ++--- interpreter/value_number.go | 26 ++++++++------ interpreter/value_path.go | 10 +++--- interpreter/value_pathcapability.go | 6 ++-- interpreter/value_placeholder.go | 2 +- interpreter/value_published.go | 6 ++-- interpreter/value_some.go | 8 ++--- interpreter/value_storage_reference.go | 20 +++++------ .../value_storagecapabilitycontroller.go | 4 +-- interpreter/value_string.go | 14 ++++---- interpreter/value_type.go | 6 ++-- interpreter/value_ufix64.go | 34 +++++++++---------- interpreter/value_uint.go | 34 +++++++++---------- interpreter/value_uint128.go | 34 +++++++++---------- interpreter/value_uint16.go | 34 +++++++++---------- interpreter/value_uint256.go | 34 +++++++++---------- interpreter/value_uint32.go | 34 +++++++++---------- interpreter/value_uint64.go | 34 +++++++++---------- interpreter/value_uint8.go | 34 +++++++++---------- interpreter/value_void.go | 6 ++-- interpreter/value_word128.go | 34 +++++++++---------- interpreter/value_word16.go | 34 +++++++++---------- interpreter/value_word256.go | 34 +++++++++---------- interpreter/value_word32.go | 34 +++++++++---------- interpreter/value_word64.go | 34 +++++++++---------- interpreter/value_word8.go | 34 +++++++++---------- 48 files changed, 499 insertions(+), 499 deletions(-) diff --git a/interpreter/interface.go b/interpreter/interface.go index 0e112f2b6e..8ea4bedadc 100644 --- a/interpreter/interface.go +++ b/interpreter/interface.go @@ -45,24 +45,11 @@ type StorageReader interface { var _ StorageReader = &Interpreter{} -type StaticTypeGetter interface { +type ValueStaticTypeContext interface { common.MemoryGauge StorageReader TypeConverter SubTypeChecker } -var _ StaticTypeGetter = &Interpreter{} - -type ComparisonContext interface { - common.MemoryGauge - StaticTypeGetter -} - -var _ ComparisonContext = &Interpreter{} - -type ArithmeticContext interface { - StaticTypeGetter -} - -var _ ArithmeticContext = &Interpreter{} +var _ ValueStaticTypeContext = &Interpreter{} diff --git a/interpreter/simplecompositevalue.go b/interpreter/simplecompositevalue.go index 1a624889e2..4985bb7f34 100644 --- a/interpreter/simplecompositevalue.go +++ b/interpreter/simplecompositevalue.go @@ -103,7 +103,7 @@ func (v *SimpleCompositeValue) Walk(_ *Interpreter, walkChild func(Value), _ Loc }) } -func (v *SimpleCompositeValue) StaticType(_ StaticTypeGetter) StaticType { +func (v *SimpleCompositeValue) StaticType(_ ValueStaticTypeContext) StaticType { return v.staticType } diff --git a/interpreter/value.go b/interpreter/value.go index fe9bd9978e..fe3828d5f0 100644 --- a/interpreter/value.go +++ b/interpreter/value.go @@ -94,7 +94,7 @@ type Value interface { isValue() Accept(interpreter *Interpreter, visitor Visitor, locationRange LocationRange) Walk(interpreter *Interpreter, walkChild func(Value), locationRange LocationRange) - StaticType(staticTypeGetter StaticTypeGetter) StaticType + StaticType(context ValueStaticTypeContext) StaticType // ConformsToStaticType returns true if the value (i.e. its dynamic type) // conforms to its own static type. // Non-container values trivially always conform to their own static type. @@ -159,16 +159,23 @@ type MemberAccessibleValue interface { SetMember(interpreter *Interpreter, locationRange LocationRange, name string, value Value) bool } +type ValueComparisonContext interface { + common.MemoryGauge + ValueStaticTypeContext +} + +var _ ValueComparisonContext = &Interpreter{} + // EquatableValue type EquatableValue interface { Value // Equal returns true if the given value is equal to this value. // If no location range is available, pass e.g. EmptyLocationRange - Equal(context ComparisonContext, locationRange LocationRange, other Value) bool + Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool } -func newValueComparator(context ComparisonContext, locationRange LocationRange) atree.ValueComparator { +func newValueComparator(context ValueComparisonContext, locationRange LocationRange) atree.ValueComparator { return func(storage atree.SlabStorage, atreeValue atree.Value, otherStorable atree.Storable) (bool, error) { value := MustConvertStoredValue(context, atreeValue) otherValue := StoredValue(context, otherStorable, storage) @@ -179,10 +186,10 @@ func newValueComparator(context ComparisonContext, locationRange LocationRange) // ComparableValue type ComparableValue interface { EquatableValue - Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue - LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue - Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue - GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue + Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue + LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue + Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue + GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue } // ResourceKindedValue diff --git a/interpreter/value_accountcapabilitycontroller.go b/interpreter/value_accountcapabilitycontroller.go index be88ce88ff..e4fa261604 100644 --- a/interpreter/value_accountcapabilitycontroller.go +++ b/interpreter/value_accountcapabilitycontroller.go @@ -96,7 +96,7 @@ func (v *AccountCapabilityControllerValue) Walk(_ *Interpreter, walkChild func(V walkChild(v.CapabilityID) } -func (v *AccountCapabilityControllerValue) StaticType(_ StaticTypeGetter) StaticType { +func (v *AccountCapabilityControllerValue) StaticType(_ ValueStaticTypeContext) StaticType { return PrimitiveStaticTypeAccountCapabilityController } @@ -136,7 +136,7 @@ func (v *AccountCapabilityControllerValue) ConformsToStaticType( return true } -func (v *AccountCapabilityControllerValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { +func (v *AccountCapabilityControllerValue) Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool { otherController, ok := other.(*AccountCapabilityControllerValue) if !ok { return false diff --git a/interpreter/value_address.go b/interpreter/value_address.go index f3ac41982b..94c726ec7f 100644 --- a/interpreter/value_address.go +++ b/interpreter/value_address.go @@ -101,8 +101,8 @@ func (AddressValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (AddressValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeAddress) +func (AddressValue) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeAddress) } func (AddressValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -122,7 +122,7 @@ func (v AddressValue) MeteredString(interpreter *Interpreter, _ SeenReferences, return v.String() } -func (v AddressValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v AddressValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherAddress, ok := other.(AddressValue) if !ok { return false diff --git a/interpreter/value_array.go b/interpreter/value_array.go index d1c9df382f..0e5075e4cc 100644 --- a/interpreter/value_array.go +++ b/interpreter/value_array.go @@ -324,7 +324,7 @@ func (v *ArrayValue) Walk( ) } -func (v *ArrayValue) StaticType(_ StaticTypeGetter) StaticType { +func (v *ArrayValue) StaticType(_ ValueStaticTypeContext) StaticType { // TODO meter return v.Type } @@ -1252,7 +1252,7 @@ func (v *ArrayValue) ConformsToStaticType( return !elementMismatch } -func (v *ArrayValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { +func (v *ArrayValue) Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool { otherArray, ok := other.(*ArrayValue) if !ok { return false diff --git a/interpreter/value_bool.go b/interpreter/value_bool.go index e0018f77f9..05bb02ad6f 100644 --- a/interpreter/value_bool.go +++ b/interpreter/value_bool.go @@ -56,8 +56,8 @@ func (BoolValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (BoolValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeBool) +func (BoolValue) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeBool) } func (BoolValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -71,7 +71,7 @@ func (v BoolValue) Negate(_ *Interpreter) BoolValue { return TrueValue } -func (v BoolValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v BoolValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherBool, ok := other.(BoolValue) if !ok { return false @@ -79,7 +79,7 @@ func (v BoolValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool return bool(v) == bool(otherBool) } -func (v BoolValue) Less(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { +func (v BoolValue) Less(_ ValueComparisonContext, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -88,7 +88,7 @@ func (v BoolValue) Less(_ ComparisonContext, other ComparableValue, _ LocationRa return !v && o } -func (v BoolValue) LessEqual(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { +func (v BoolValue) LessEqual(_ ValueComparisonContext, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -97,7 +97,7 @@ func (v BoolValue) LessEqual(_ ComparisonContext, other ComparableValue, _ Locat return !v || o } -func (v BoolValue) Greater(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { +func (v BoolValue) Greater(_ ValueComparisonContext, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -106,7 +106,7 @@ func (v BoolValue) Greater(_ ComparisonContext, other ComparableValue, _ Locatio return v && !o } -func (v BoolValue) GreaterEqual(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { +func (v BoolValue) GreaterEqual(_ ValueComparisonContext, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) diff --git a/interpreter/value_capability.go b/interpreter/value_capability.go index f2f26625c2..fee32da09a 100644 --- a/interpreter/value_capability.go +++ b/interpreter/value_capability.go @@ -108,9 +108,9 @@ func (v *IDCapabilityValue) Walk(_ *Interpreter, walkChild func(Value), _ Locati walkChild(v.address) } -func (v *IDCapabilityValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { +func (v *IDCapabilityValue) StaticType(context ValueStaticTypeContext) StaticType { return NewCapabilityStaticType( - staticTypeGetter, + context, v.BorrowType, ) } @@ -181,7 +181,7 @@ func (v *IDCapabilityValue) ConformsToStaticType( return true } -func (v *IDCapabilityValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { +func (v *IDCapabilityValue) Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool { otherCapability, ok := other.(*IDCapabilityValue) if !ok { return false diff --git a/interpreter/value_character.go b/interpreter/value_character.go index b5a1491d0f..0714481160 100644 --- a/interpreter/value_character.go +++ b/interpreter/value_character.go @@ -86,8 +86,8 @@ func (CharacterValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (CharacterValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeCharacter) +func (CharacterValue) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeCharacter) } func (CharacterValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -108,7 +108,7 @@ func (v CharacterValue) MeteredString(interpreter *Interpreter, _ SeenReferences return v.String() } -func (v CharacterValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v CharacterValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherChar, ok := other.(CharacterValue) if !ok { return false @@ -116,7 +116,7 @@ func (v CharacterValue) Equal(_ ComparisonContext, _ LocationRange, other Value) return v.Str == otherChar.Str } -func (v CharacterValue) Less(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { +func (v CharacterValue) Less(_ ValueComparisonContext, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) @@ -124,7 +124,7 @@ func (v CharacterValue) Less(_ ComparisonContext, other ComparableValue, _ Locat return v.Str < otherChar.Str } -func (v CharacterValue) LessEqual(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { +func (v CharacterValue) LessEqual(_ ValueComparisonContext, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) @@ -132,7 +132,7 @@ func (v CharacterValue) LessEqual(_ ComparisonContext, other ComparableValue, _ return v.Str <= otherChar.Str } -func (v CharacterValue) Greater(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { +func (v CharacterValue) Greater(_ ValueComparisonContext, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) @@ -140,7 +140,7 @@ func (v CharacterValue) Greater(_ ComparisonContext, other ComparableValue, _ Lo return v.Str > otherChar.Str } -func (v CharacterValue) GreaterEqual(_ ComparisonContext, other ComparableValue, _ LocationRange) BoolValue { +func (v CharacterValue) GreaterEqual(_ ValueComparisonContext, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) diff --git a/interpreter/value_composite.go b/interpreter/value_composite.go index a92dd86180..d3e649661a 100644 --- a/interpreter/value_composite.go +++ b/interpreter/value_composite.go @@ -264,12 +264,12 @@ func (v *CompositeValue) Walk(interpreter *Interpreter, walkChild func(Value), l }, locationRange) } -func (v *CompositeValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { +func (v *CompositeValue) StaticType(context ValueStaticTypeContext) StaticType { if v.staticType == nil { // NOTE: Instead of using NewCompositeStaticType, which always generates the type ID, // use the TypeID accessor, which may return an already computed type ID v.staticType = NewCompositeStaticType( - staticTypeGetter, + context, v.Location, v.QualifiedIdentifier, v.TypeID(), @@ -875,7 +875,7 @@ func (v *CompositeValue) GetField(memoryGauge common.MemoryGauge, name string) V return MustConvertStoredValue(memoryGauge, storedValue) } -func (v *CompositeValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { +func (v *CompositeValue) Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool { otherComposite, ok := other.(*CompositeValue) if !ok { return false diff --git a/interpreter/value_dictionary.go b/interpreter/value_dictionary.go index 44abd25a25..7bf54e1385 100644 --- a/interpreter/value_dictionary.go +++ b/interpreter/value_dictionary.go @@ -441,7 +441,7 @@ func (v *DictionaryValue) Walk(interpreter *Interpreter, walkChild func(Value), ) } -func (v *DictionaryValue) StaticType(_ StaticTypeGetter) StaticType { +func (v *DictionaryValue) StaticType(_ ValueStaticTypeContext) StaticType { // TODO meter return v.Type } @@ -593,7 +593,7 @@ func (v *DictionaryValue) ContainsKey( } func (v *DictionaryValue) Get( - context ComparisonContext, + context ValueComparisonContext, locationRange LocationRange, keyValue Value, ) (Value, bool) { @@ -1214,7 +1214,7 @@ func (v *DictionaryValue) ConformsToStaticType( } } -func (v *DictionaryValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { +func (v *DictionaryValue) Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool { otherDictionary, ok := other.(*DictionaryValue) if !ok { diff --git a/interpreter/value_ephemeral_reference.go b/interpreter/value_ephemeral_reference.go index 0e062074d9..e4643273aa 100644 --- a/interpreter/value_ephemeral_reference.go +++ b/interpreter/value_ephemeral_reference.go @@ -111,11 +111,11 @@ func (v *EphemeralReferenceValue) MeteredString(interpreter *Interpreter, seenRe return v.Value.MeteredString(interpreter, seenReferences, locationRange) } -func (v *EphemeralReferenceValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { +func (v *EphemeralReferenceValue) StaticType(context ValueStaticTypeContext) StaticType { return NewReferenceStaticType( - staticTypeGetter, + context, v.Authorization, - v.Value.StaticType(staticTypeGetter), + v.Value.StaticType(context), ) } @@ -241,7 +241,7 @@ func (v *EphemeralReferenceValue) RemoveTypeKey( RemoveTypeKey(interpreter, locationRange, key) } -func (v *EphemeralReferenceValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v *EphemeralReferenceValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherReference, ok := other.(*EphemeralReferenceValue) if !ok || v.Value != otherReference.Value || diff --git a/interpreter/value_fix64.go b/interpreter/value_fix64.go index af0c6846bc..fb2781d346 100644 --- a/interpreter/value_fix64.go +++ b/interpreter/value_fix64.go @@ -93,8 +93,8 @@ func (Fix64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Fix64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeFix64) +func (Fix64Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeFix64) } func (Fix64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -123,7 +123,7 @@ func (v Fix64Value) ToInt(_ LocationRange) int { return int(v / sema.Fix64Factor) } -func (v Fix64Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { +func (v Fix64Value) Negate(context NumberValueArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt64 { panic(OverflowError{ @@ -138,7 +138,7 @@ func (v Fix64Value) Negate(context ArithmeticContext, locationRange LocationRang return NewFix64Value(context, valueGetter) } -func (v Fix64Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -156,7 +156,7 @@ func (v Fix64Value) Plus(context ArithmeticContext, other NumberValue, locationR return NewFix64Value(context, valueGetter) } -func (v Fix64Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -180,7 +180,7 @@ func (v Fix64Value) SaturatingPlus(context ArithmeticContext, other NumberValue, return NewFix64Value(context, valueGetter) } -func (v Fix64Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -209,7 +209,7 @@ func (v Fix64Value) Minus(context ArithmeticContext, other NumberValue, location return NewFix64Value(context, valueGetter) } -func (v Fix64Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -236,7 +236,7 @@ func (v Fix64Value) SaturatingMinus(context ArithmeticContext, other NumberValue var minInt64Big = big.NewInt(math.MinInt64) var maxInt64Big = big.NewInt(math.MaxInt64) -func (v Fix64Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -270,7 +270,7 @@ func (v Fix64Value) Mul(context ArithmeticContext, other NumberValue, locationRa return NewFix64Value(context, valueGetter) } -func (v Fix64Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -300,7 +300,7 @@ func (v Fix64Value) SaturatingMul(context ArithmeticContext, other NumberValue, return NewFix64Value(context, valueGetter) } -func (v Fix64Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -334,7 +334,7 @@ func (v Fix64Value) Div(context ArithmeticContext, other NumberValue, locationRa return NewFix64Value(context, valueGetter) } -func (v Fix64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -364,7 +364,7 @@ func (v Fix64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return NewFix64Value(context, valueGetter) } -func (v Fix64Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Fix64Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -400,7 +400,7 @@ func (v Fix64Value) Mod(context ArithmeticContext, other NumberValue, locationRa ) } -func (v Fix64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Fix64Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -414,7 +414,7 @@ func (v Fix64Value) Less(context ComparisonContext, other ComparableValue, locat return AsBoolValue(v < o) } -func (v Fix64Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Fix64Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -428,7 +428,7 @@ func (v Fix64Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v Fix64Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Fix64Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -442,7 +442,7 @@ func (v Fix64Value) Greater(context ComparisonContext, other ComparableValue, lo return AsBoolValue(v > o) } -func (v Fix64Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Fix64Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ @@ -456,7 +456,7 @@ func (v Fix64Value) GreaterEqual(context ComparisonContext, other ComparableValu return AsBoolValue(v >= o) } -func (v Fix64Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Fix64Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherFix64, ok := other.(Fix64Value) if !ok { return false diff --git a/interpreter/value_function.go b/interpreter/value_function.go index 2d17d4a0ab..9ecc4cf462 100644 --- a/interpreter/value_function.go +++ b/interpreter/value_function.go @@ -103,8 +103,8 @@ func (f *InterpretedFunctionValue) Walk(_ *Interpreter, _ func(Value), _ Locatio // NO-OP } -func (f *InterpretedFunctionValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return ConvertSemaToStaticType(staticTypeGetter, f.Type) +func (f *InterpretedFunctionValue) StaticType(context ValueStaticTypeContext) StaticType { + return ConvertSemaToStaticType(context, f.Type) } func (*InterpretedFunctionValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -237,8 +237,8 @@ func (f *HostFunctionValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) // NO-OP } -func (f *HostFunctionValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return ConvertSemaToStaticType(staticTypeGetter, f.Type) +func (f *HostFunctionValue) StaticType(context ValueStaticTypeContext) StaticType { + return ConvertSemaToStaticType(context, f.Type) } func (*HostFunctionValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -413,8 +413,8 @@ func (f BoundFunctionValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) // NO-OP } -func (f BoundFunctionValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return f.Function.StaticType(staticTypeGetter) +func (f BoundFunctionValue) StaticType(context ValueStaticTypeContext) StaticType { + return f.Function.StaticType(context) } func (BoundFunctionValue) IsImportable(_ *Interpreter, _ LocationRange) bool { diff --git a/interpreter/value_int.go b/interpreter/value_int.go index 0a903387dc..1d86803d59 100644 --- a/interpreter/value_int.go +++ b/interpreter/value_int.go @@ -109,8 +109,8 @@ func (IntValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (IntValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt) +func (IntValue) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeInt) } func (IntValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -171,7 +171,7 @@ func (v IntValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ Lo return v.String() } -func (v IntValue) Negate(context ArithmeticContext, _ LocationRange) NumberValue { +func (v IntValue) Negate(context NumberValueArithmeticContext, _ LocationRange) NumberValue { return NewIntValueFromBigInt( context, common.NewNegateBigIntMemoryUsage(v.BigInt), @@ -181,7 +181,7 @@ func (v IntValue) Negate(context ArithmeticContext, _ LocationRange) NumberValue ) } -func (v IntValue) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ @@ -202,7 +202,7 @@ func (v IntValue) Plus(context ArithmeticContext, other NumberValue, locationRan ) } -func (v IntValue) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -218,7 +218,7 @@ func (v IntValue) SaturatingPlus(context ArithmeticContext, other NumberValue, l return v.Plus(context, other, locationRange) } -func (v IntValue) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ @@ -239,7 +239,7 @@ func (v IntValue) Minus(context ArithmeticContext, other NumberValue, locationRa ) } -func (v IntValue) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -255,7 +255,7 @@ func (v IntValue) SaturatingMinus(context ArithmeticContext, other NumberValue, return v.Minus(context, other, locationRange) } -func (v IntValue) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ @@ -282,7 +282,7 @@ func (v IntValue) Mod(context ArithmeticContext, other NumberValue, locationRang ) } -func (v IntValue) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ @@ -303,7 +303,7 @@ func (v IntValue) Mul(context ArithmeticContext, other NumberValue, locationRang ) } -func (v IntValue) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -319,7 +319,7 @@ func (v IntValue) SaturatingMul(context ArithmeticContext, other NumberValue, lo return v.Mul(context, other, locationRange) } -func (v IntValue) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ @@ -346,7 +346,7 @@ func (v IntValue) Div(context ArithmeticContext, other NumberValue, locationRang ) } -func (v IntValue) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v IntValue) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -362,7 +362,7 @@ func (v IntValue) SaturatingDiv(context ArithmeticContext, other NumberValue, lo return v.Div(context, other, locationRange) } -func (v IntValue) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v IntValue) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ @@ -377,7 +377,7 @@ func (v IntValue) Less(context ComparisonContext, other ComparableValue, locatio return AsBoolValue(cmp == -1) } -func (v IntValue) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v IntValue) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ @@ -392,7 +392,7 @@ func (v IntValue) LessEqual(context ComparisonContext, other ComparableValue, lo return AsBoolValue(cmp <= 0) } -func (v IntValue) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v IntValue) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ @@ -408,7 +408,7 @@ func (v IntValue) Greater(context ComparisonContext, other ComparableValue, loca } -func (v IntValue) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v IntValue) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ @@ -423,7 +423,7 @@ func (v IntValue) GreaterEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(cmp >= 0) } -func (v IntValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v IntValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(IntValue) if !ok { return false diff --git a/interpreter/value_int128.go b/interpreter/value_int128.go index 96ed47ffe8..c046286ecf 100644 --- a/interpreter/value_int128.go +++ b/interpreter/value_int128.go @@ -82,8 +82,8 @@ func (Int128Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int128Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt128) +func (Int128Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeInt128) } func (Int128Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -126,7 +126,7 @@ func (v Int128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ return v.String() } -func (v Int128Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { +func (v Int128Value) Negate(context NumberValueArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C // if v == Int128TypeMinIntBig { // ... @@ -144,7 +144,7 @@ func (v Int128Value) Negate(context ArithmeticContext, locationRange LocationRan return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -186,7 +186,7 @@ func (v Int128Value) Plus(context ArithmeticContext, other NumberValue, location return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -224,7 +224,7 @@ func (v Int128Value) SaturatingPlus(context ArithmeticContext, other NumberValue return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -266,7 +266,7 @@ func (v Int128Value) Minus(context ArithmeticContext, other NumberValue, locatio return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -304,7 +304,7 @@ func (v Int128Value) SaturatingMinus(context ArithmeticContext, other NumberValu return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -331,7 +331,7 @@ func (v Int128Value) Mod(context ArithmeticContext, other NumberValue, locationR return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -361,7 +361,7 @@ func (v Int128Value) Mul(context ArithmeticContext, other NumberValue, locationR return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -387,7 +387,7 @@ func (v Int128Value) SaturatingMul(context ArithmeticContext, other NumberValue, return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -425,7 +425,7 @@ func (v Int128Value) Div(context ArithmeticContext, other NumberValue, locationR return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int128Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -461,7 +461,7 @@ func (v Int128Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return NewInt128ValueFromBigInt(context, valueGetter) } -func (v Int128Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int128Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -476,7 +476,7 @@ func (v Int128Value) Less(context ComparisonContext, other ComparableValue, loca return AsBoolValue(cmp == -1) } -func (v Int128Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int128Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -491,7 +491,7 @@ func (v Int128Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(cmp <= 0) } -func (v Int128Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int128Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -506,7 +506,7 @@ func (v Int128Value) Greater(context ComparisonContext, other ComparableValue, l return AsBoolValue(cmp == 1) } -func (v Int128Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int128Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ @@ -521,7 +521,7 @@ func (v Int128Value) GreaterEqual(context ComparisonContext, other ComparableVal return AsBoolValue(cmp >= 0) } -func (v Int128Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Int128Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(Int128Value) if !ok { return false diff --git a/interpreter/value_int16.go b/interpreter/value_int16.go index aa15c5e670..90e798327d 100644 --- a/interpreter/value_int16.go +++ b/interpreter/value_int16.go @@ -69,8 +69,8 @@ func (Int16Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int16Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt16) +func (Int16Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeInt16) } func (Int16Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -99,7 +99,7 @@ func (v Int16Value) ToInt(_ LocationRange) int { return int(v) } -func (v Int16Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { +func (v Int16Value) Negate(context NumberValueArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt16 { panic(OverflowError{ @@ -114,7 +114,7 @@ func (v Int16Value) Negate(context ArithmeticContext, locationRange LocationRang return NewInt16Value(context, valueGetter) } -func (v Int16Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -143,7 +143,7 @@ func (v Int16Value) Plus(context ArithmeticContext, other NumberValue, locationR return NewInt16Value(context, valueGetter) } -func (v Int16Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -167,7 +167,7 @@ func (v Int16Value) SaturatingPlus(context ArithmeticContext, other NumberValue, return NewInt16Value(context, valueGetter) } -func (v Int16Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -196,7 +196,7 @@ func (v Int16Value) Minus(context ArithmeticContext, other NumberValue, location return NewInt16Value(context, valueGetter) } -func (v Int16Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -220,7 +220,7 @@ func (v Int16Value) SaturatingMinus(context ArithmeticContext, other NumberValue return NewInt16Value(context, valueGetter) } -func (v Int16Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -245,7 +245,7 @@ func (v Int16Value) Mod(context ArithmeticContext, other NumberValue, locationRa return NewInt16Value(context, valueGetter) } -func (v Int16Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -298,7 +298,7 @@ func (v Int16Value) Mul(context ArithmeticContext, other NumberValue, locationRa return NewInt16Value(context, valueGetter) } -func (v Int16Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -342,7 +342,7 @@ func (v Int16Value) SaturatingMul(context ArithmeticContext, other NumberValue, return NewInt16Value(context, valueGetter) } -func (v Int16Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -372,7 +372,7 @@ func (v Int16Value) Div(context ArithmeticContext, other NumberValue, locationRa return NewInt16Value(context, valueGetter) } -func (v Int16Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int16Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -399,7 +399,7 @@ func (v Int16Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return NewInt16Value(context, valueGetter) } -func (v Int16Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int16Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -413,7 +413,7 @@ func (v Int16Value) Less(context ComparisonContext, other ComparableValue, locat return AsBoolValue(v < o) } -func (v Int16Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int16Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -427,7 +427,7 @@ func (v Int16Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v Int16Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int16Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -441,7 +441,7 @@ func (v Int16Value) Greater(context ComparisonContext, other ComparableValue, lo return AsBoolValue(v > o) } -func (v Int16Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int16Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ @@ -455,7 +455,7 @@ func (v Int16Value) GreaterEqual(context ComparisonContext, other ComparableValu return AsBoolValue(v >= o) } -func (v Int16Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Int16Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt16, ok := other.(Int16Value) if !ok { return false diff --git a/interpreter/value_int256.go b/interpreter/value_int256.go index 2943a082b6..48aa20a943 100644 --- a/interpreter/value_int256.go +++ b/interpreter/value_int256.go @@ -82,8 +82,8 @@ func (Int256Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int256Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt256) +func (Int256Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeInt256) } func (Int256Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -126,7 +126,7 @@ func (v Int256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ return v.String() } -func (v Int256Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { +func (v Int256Value) Negate(context NumberValueArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C // if v == Int256TypeMinIntBig { // ... @@ -144,7 +144,7 @@ func (v Int256Value) Negate(context ArithmeticContext, locationRange LocationRan return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -186,7 +186,7 @@ func (v Int256Value) Plus(context ArithmeticContext, other NumberValue, location return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -224,7 +224,7 @@ func (v Int256Value) SaturatingPlus(context ArithmeticContext, other NumberValue return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -266,7 +266,7 @@ func (v Int256Value) Minus(context ArithmeticContext, other NumberValue, locatio return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -304,7 +304,7 @@ func (v Int256Value) SaturatingMinus(context ArithmeticContext, other NumberValu return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -331,7 +331,7 @@ func (v Int256Value) Mod(context ArithmeticContext, other NumberValue, locationR return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -361,7 +361,7 @@ func (v Int256Value) Mul(context ArithmeticContext, other NumberValue, locationR return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -387,7 +387,7 @@ func (v Int256Value) SaturatingMul(context ArithmeticContext, other NumberValue, return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -424,7 +424,7 @@ func (v Int256Value) Div(context ArithmeticContext, other NumberValue, locationR return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int256Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -459,7 +459,7 @@ func (v Int256Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return NewInt256ValueFromBigInt(context, valueGetter) } -func (v Int256Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int256Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -474,7 +474,7 @@ func (v Int256Value) Less(context ComparisonContext, other ComparableValue, loca return AsBoolValue(cmp == -1) } -func (v Int256Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int256Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -489,7 +489,7 @@ func (v Int256Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(cmp <= 0) } -func (v Int256Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int256Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -504,7 +504,7 @@ func (v Int256Value) Greater(context ComparisonContext, other ComparableValue, l return AsBoolValue(cmp == 1) } -func (v Int256Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int256Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ @@ -519,7 +519,7 @@ func (v Int256Value) GreaterEqual(context ComparisonContext, other ComparableVal return AsBoolValue(cmp >= 0) } -func (v Int256Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Int256Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(Int256Value) if !ok { return false diff --git a/interpreter/value_int32.go b/interpreter/value_int32.go index b7554a74e3..41058c6fbf 100644 --- a/interpreter/value_int32.go +++ b/interpreter/value_int32.go @@ -69,8 +69,8 @@ func (Int32Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int32Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt32) +func (Int32Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeInt32) } func (Int32Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -99,7 +99,7 @@ func (v Int32Value) ToInt(_ LocationRange) int { return int(v) } -func (v Int32Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { +func (v Int32Value) Negate(context NumberValueArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt32 { panic(OverflowError{ @@ -114,7 +114,7 @@ func (v Int32Value) Negate(context ArithmeticContext, locationRange LocationRang return NewInt32Value(context, valueGetter) } -func (v Int32Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -143,7 +143,7 @@ func (v Int32Value) Plus(context ArithmeticContext, other NumberValue, locationR return NewInt32Value(context, valueGetter) } -func (v Int32Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -167,7 +167,7 @@ func (v Int32Value) SaturatingPlus(context ArithmeticContext, other NumberValue, return NewInt32Value(context, valueGetter) } -func (v Int32Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -196,7 +196,7 @@ func (v Int32Value) Minus(context ArithmeticContext, other NumberValue, location return NewInt32Value(context, valueGetter) } -func (v Int32Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -220,7 +220,7 @@ func (v Int32Value) SaturatingMinus(context ArithmeticContext, other NumberValue return NewInt32Value(context, valueGetter) } -func (v Int32Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -245,7 +245,7 @@ func (v Int32Value) Mod(context ArithmeticContext, other NumberValue, locationRa return NewInt32Value(context, valueGetter) } -func (v Int32Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -298,7 +298,7 @@ func (v Int32Value) Mul(context ArithmeticContext, other NumberValue, locationRa return NewInt32Value(context, valueGetter) } -func (v Int32Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -342,7 +342,7 @@ func (v Int32Value) SaturatingMul(context ArithmeticContext, other NumberValue, return NewInt32Value(context, valueGetter) } -func (v Int32Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -372,7 +372,7 @@ func (v Int32Value) Div(context ArithmeticContext, other NumberValue, locationRa return NewInt32Value(context, valueGetter) } -func (v Int32Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int32Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -400,7 +400,7 @@ func (v Int32Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return NewInt32Value(context, valueGetter) } -func (v Int32Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int32Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -414,7 +414,7 @@ func (v Int32Value) Less(context ComparisonContext, other ComparableValue, locat return AsBoolValue(v < o) } -func (v Int32Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int32Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -428,7 +428,7 @@ func (v Int32Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v Int32Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int32Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -442,7 +442,7 @@ func (v Int32Value) Greater(context ComparisonContext, other ComparableValue, lo return AsBoolValue(v > o) } -func (v Int32Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int32Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ @@ -456,7 +456,7 @@ func (v Int32Value) GreaterEqual(context ComparisonContext, other ComparableValu return AsBoolValue(v >= o) } -func (v Int32Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Int32Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt32, ok := other.(Int32Value) if !ok { return false diff --git a/interpreter/value_int64.go b/interpreter/value_int64.go index 1e855ebedc..45e6d54b17 100644 --- a/interpreter/value_int64.go +++ b/interpreter/value_int64.go @@ -66,8 +66,8 @@ func (Int64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt64) +func (Int64Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeInt64) } func (Int64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -96,7 +96,7 @@ func (v Int64Value) ToInt(_ LocationRange) int { return int(v) } -func (v Int64Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { +func (v Int64Value) Negate(context NumberValueArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt64 { panic(OverflowError{ @@ -125,7 +125,7 @@ func safeAddInt64(a, b int64, locationRange LocationRange) int64 { return a + b } -func (v Int64Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -143,7 +143,7 @@ func (v Int64Value) Plus(context ArithmeticContext, other NumberValue, locationR return NewInt64Value(context, valueGetter) } -func (v Int64Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -167,7 +167,7 @@ func (v Int64Value) SaturatingPlus(context ArithmeticContext, other NumberValue, return NewInt64Value(context, valueGetter) } -func (v Int64Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -196,7 +196,7 @@ func (v Int64Value) Minus(context ArithmeticContext, other NumberValue, location return NewInt64Value(context, valueGetter) } -func (v Int64Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -220,7 +220,7 @@ func (v Int64Value) SaturatingMinus(context ArithmeticContext, other NumberValue return NewInt64Value(context, valueGetter) } -func (v Int64Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -245,7 +245,7 @@ func (v Int64Value) Mod(context ArithmeticContext, other NumberValue, locationRa return NewInt64Value(context, valueGetter) } -func (v Int64Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -298,7 +298,7 @@ func (v Int64Value) Mul(context ArithmeticContext, other NumberValue, locationRa return NewInt64Value(context, valueGetter) } -func (v Int64Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -342,7 +342,7 @@ func (v Int64Value) SaturatingMul(context ArithmeticContext, other NumberValue, return NewInt64Value(context, valueGetter) } -func (v Int64Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -372,7 +372,7 @@ func (v Int64Value) Div(context ArithmeticContext, other NumberValue, locationRa return NewInt64Value(context, valueGetter) } -func (v Int64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int64Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -399,7 +399,7 @@ func (v Int64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return NewInt64Value(context, valueGetter) } -func (v Int64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int64Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -413,7 +413,7 @@ func (v Int64Value) Less(context ComparisonContext, other ComparableValue, locat return AsBoolValue(v < o) } -func (v Int64Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int64Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -427,7 +427,7 @@ func (v Int64Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v Int64Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int64Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -442,7 +442,7 @@ func (v Int64Value) Greater(context ComparisonContext, other ComparableValue, lo } -func (v Int64Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int64Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ @@ -456,7 +456,7 @@ func (v Int64Value) GreaterEqual(context ComparisonContext, other ComparableValu return AsBoolValue(v >= o) } -func (v Int64Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Int64Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt64, ok := other.(Int64Value) if !ok { return false diff --git a/interpreter/value_int8.go b/interpreter/value_int8.go index a5acdf7842..6af11f28fe 100644 --- a/interpreter/value_int8.go +++ b/interpreter/value_int8.go @@ -67,8 +67,8 @@ func (Int8Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Int8Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeInt8) +func (Int8Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeInt8) } func (Int8Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -97,7 +97,7 @@ func (v Int8Value) ToInt(_ LocationRange) int { return int(v) } -func (v Int8Value) Negate(context ArithmeticContext, locationRange LocationRange) NumberValue { +func (v Int8Value) Negate(context NumberValueArithmeticContext, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt8 { panic(OverflowError{ @@ -112,7 +112,7 @@ func (v Int8Value) Negate(context ArithmeticContext, locationRange LocationRange return NewInt8Value(context, valueGetter) } -func (v Int8Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -141,7 +141,7 @@ func (v Int8Value) Plus(context ArithmeticContext, other NumberValue, locationRa return NewInt8Value(context, valueGetter) } -func (v Int8Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -165,7 +165,7 @@ func (v Int8Value) SaturatingPlus(context ArithmeticContext, other NumberValue, return NewInt8Value(context, valueGetter) } -func (v Int8Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -194,7 +194,7 @@ func (v Int8Value) Minus(context ArithmeticContext, other NumberValue, locationR return NewInt8Value(context, valueGetter) } -func (v Int8Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -218,7 +218,7 @@ func (v Int8Value) SaturatingMinus(context ArithmeticContext, other NumberValue, return NewInt8Value(context, valueGetter) } -func (v Int8Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -243,7 +243,7 @@ func (v Int8Value) Mod(context ArithmeticContext, other NumberValue, locationRan return NewInt8Value(context, valueGetter) } -func (v Int8Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -296,7 +296,7 @@ func (v Int8Value) Mul(context ArithmeticContext, other NumberValue, locationRan return NewInt8Value(context, valueGetter) } -func (v Int8Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -341,7 +341,7 @@ func (v Int8Value) SaturatingMul(context ArithmeticContext, other NumberValue, l return NewInt8Value(context, valueGetter) } -func (v Int8Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -371,7 +371,7 @@ func (v Int8Value) Div(context ArithmeticContext, other NumberValue, locationRan return NewInt8Value(context, valueGetter) } -func (v Int8Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Int8Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -398,7 +398,7 @@ func (v Int8Value) SaturatingDiv(context ArithmeticContext, other NumberValue, l return NewInt8Value(context, valueGetter) } -func (v Int8Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int8Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -412,7 +412,7 @@ func (v Int8Value) Less(context ComparisonContext, other ComparableValue, locati return AsBoolValue(v < o) } -func (v Int8Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int8Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -426,7 +426,7 @@ func (v Int8Value) LessEqual(context ComparisonContext, other ComparableValue, l return AsBoolValue(v <= o) } -func (v Int8Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int8Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -440,7 +440,7 @@ func (v Int8Value) Greater(context ComparisonContext, other ComparableValue, loc return AsBoolValue(v > o) } -func (v Int8Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Int8Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ @@ -454,7 +454,7 @@ func (v Int8Value) GreaterEqual(context ComparisonContext, other ComparableValue return AsBoolValue(v >= o) } -func (v Int8Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Int8Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt8, ok := other.(Int8Value) if !ok { return false diff --git a/interpreter/value_link.go b/interpreter/value_link.go index 5bebacb76d..3411fc6379 100644 --- a/interpreter/value_link.go +++ b/interpreter/value_link.go @@ -59,7 +59,7 @@ func (v PathLinkValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { panic(errors.NewUnreachableError()) } -func (v PathLinkValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { +func (v PathLinkValue) StaticType(context ValueStaticTypeContext) StaticType { // When iterating over public/private paths, // the values at these paths are PathLinkValues, // placed there by the `link` function. @@ -67,7 +67,7 @@ func (v PathLinkValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType // These are loaded as links, however, // for the purposes of checking their type, // we treat them as capabilities - return NewCapabilityStaticType(staticTypeGetter, v.Type) + return NewCapabilityStaticType(context, v.Type) } func (PathLinkValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -98,7 +98,7 @@ func (v PathLinkValue) ConformsToStaticType( panic(errors.NewUnreachableError()) } -func (v PathLinkValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { +func (v PathLinkValue) Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool { otherLink, ok := other.(PathLinkValue) if !ok { return false @@ -184,7 +184,7 @@ func (AccountLinkValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { panic(errors.NewUnreachableError()) } -func (v AccountLinkValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { +func (v AccountLinkValue) StaticType(context ValueStaticTypeContext) StaticType { // When iterating over public/private paths, // the values at these paths are AccountLinkValues, // placed there by the `linkAccount` function. @@ -193,9 +193,9 @@ func (v AccountLinkValue) StaticType(staticTypeGetter StaticTypeGetter) StaticTy // for the purposes of checking their type, // we treat them as capabilities return NewCapabilityStaticType( - staticTypeGetter, + context, NewReferenceStaticType( - staticTypeGetter, + context, FullyEntitledAccountAccess, PrimitiveStaticTypeAccount, ), @@ -226,7 +226,7 @@ func (v AccountLinkValue) ConformsToStaticType( panic(errors.NewUnreachableError()) } -func (v AccountLinkValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v AccountLinkValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { _, ok := other.(AccountLinkValue) return ok } diff --git a/interpreter/value_nil.go b/interpreter/value_nil.go index 40d1029f71..c6d7ae7846 100644 --- a/interpreter/value_nil.go +++ b/interpreter/value_nil.go @@ -51,10 +51,10 @@ func (NilValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (NilValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { +func (NilValue) StaticType(context ValueStaticTypeContext) StaticType { return NewOptionalStaticType( - staticTypeGetter, - NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeNever), + context, + NewPrimitiveStaticType(context, PrimitiveStaticTypeNever), ) } @@ -125,7 +125,7 @@ func (v NilValue) ConformsToStaticType( return true } -func (v NilValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v NilValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { _, ok := other.(NilValue) return ok } diff --git a/interpreter/value_number.go b/interpreter/value_number.go index 25fe93990f..a754ec6c97 100644 --- a/interpreter/value_number.go +++ b/interpreter/value_number.go @@ -26,20 +26,26 @@ import ( "github.com/onflow/cadence/sema" ) +type NumberValueArithmeticContext interface { + ValueStaticTypeContext +} + +var _ NumberValueArithmeticContext = &Interpreter{} + // NumberValue type NumberValue interface { ComparableValue ToInt(locationRange LocationRange) int - Negate(context ArithmeticContext, locationRange LocationRange) NumberValue - Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue - SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue - Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue - SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue - Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue - Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue - SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue - Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue - SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + Negate(context NumberValueArithmeticContext, locationRange LocationRange) NumberValue + Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue + SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue ToBigEndianBytes() []byte } diff --git a/interpreter/value_path.go b/interpreter/value_path.go index a2673994e7..f933b765f9 100644 --- a/interpreter/value_path.go +++ b/interpreter/value_path.go @@ -65,14 +65,14 @@ func (PathValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (v PathValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { +func (v PathValue) StaticType(context ValueStaticTypeContext) StaticType { switch v.Domain { case common.PathDomainStorage: - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeStoragePath) + return NewPrimitiveStaticType(context, PrimitiveStaticTypeStoragePath) case common.PathDomainPublic: - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypePublicPath) + return NewPrimitiveStaticType(context, PrimitiveStaticTypePublicPath) case common.PathDomainPrivate: - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypePrivatePath) + return NewPrimitiveStaticType(context, PrimitiveStaticTypePrivatePath) default: panic(errors.NewUnreachableError()) } @@ -157,7 +157,7 @@ func (v PathValue) ConformsToStaticType( return true } -func (v PathValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v PathValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherPath, ok := other.(PathValue) if !ok { return false diff --git a/interpreter/value_pathcapability.go b/interpreter/value_pathcapability.go index f39572d01f..8181b779a3 100644 --- a/interpreter/value_pathcapability.go +++ b/interpreter/value_pathcapability.go @@ -69,9 +69,9 @@ func (v *PathCapabilityValue) Walk(_ *Interpreter, walkChild func(Value), _ Loca walkChild(v.Path) } -func (v *PathCapabilityValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { +func (v *PathCapabilityValue) StaticType(context ValueStaticTypeContext) StaticType { return NewCapabilityStaticType( - staticTypeGetter, + context, v.BorrowType, ) } @@ -199,7 +199,7 @@ func (v *PathCapabilityValue) ConformsToStaticType( return true } -func (v *PathCapabilityValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { +func (v *PathCapabilityValue) Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool { otherCapability, ok := other.(*PathCapabilityValue) if !ok { return false diff --git a/interpreter/value_placeholder.go b/interpreter/value_placeholder.go index 30a2d8c5f9..8eb94d7cb5 100644 --- a/interpreter/value_placeholder.go +++ b/interpreter/value_placeholder.go @@ -51,7 +51,7 @@ func (f placeholderValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (f placeholderValue) StaticType(_ StaticTypeGetter) StaticType { +func (f placeholderValue) StaticType(_ ValueStaticTypeContext) StaticType { return PrimitiveStaticTypeNever } diff --git a/interpreter/value_published.go b/interpreter/value_published.go index a9e66a5d12..de2c4e1505 100644 --- a/interpreter/value_published.go +++ b/interpreter/value_published.go @@ -53,10 +53,10 @@ func (v *PublishedValue) Accept(interpreter *Interpreter, visitor Visitor, _ Loc visitor.VisitPublishedValue(interpreter, v) } -func (v *PublishedValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { +func (v *PublishedValue) StaticType(context ValueStaticTypeContext) StaticType { // checking the static type of a published value should show us the // static type of the underlying value - return v.Value.StaticType(staticTypeGetter) + return v.Value.StaticType(context) } func (*PublishedValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -98,7 +98,7 @@ func (v *PublishedValue) ConformsToStaticType( return false } -func (v *PublishedValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { +func (v *PublishedValue) Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool { otherValue, ok := other.(*PublishedValue) if !ok { return false diff --git a/interpreter/value_some.go b/interpreter/value_some.go index be1f5c4466..668b257bd0 100644 --- a/interpreter/value_some.go +++ b/interpreter/value_some.go @@ -66,17 +66,17 @@ func (v *SomeValue) Walk(_ *Interpreter, walkChild func(Value), _ LocationRange) walkChild(v.value) } -func (v *SomeValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { +func (v *SomeValue) StaticType(context ValueStaticTypeContext) StaticType { if v.isDestroyed { return nil } - innerType := v.value.StaticType(staticTypeGetter) + innerType := v.value.StaticType(context) if innerType == nil { return nil } return NewOptionalStaticType( - staticTypeGetter, + context, innerType, ) } @@ -194,7 +194,7 @@ func (v *SomeValue) ConformsToStaticType( ) } -func (v *SomeValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { +func (v *SomeValue) Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool { otherSome, ok := other.(*SomeValue) if !ok { return false diff --git a/interpreter/value_storage_reference.go b/interpreter/value_storage_reference.go index 0f8f34c723..447268aa17 100644 --- a/interpreter/value_storage_reference.go +++ b/interpreter/value_storage_reference.go @@ -98,8 +98,8 @@ func (v *StorageReferenceValue) MeteredString(interpreter *Interpreter, _ SeenRe return v.String() } -func (v *StorageReferenceValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - referencedValue, err := v.dereference(staticTypeGetter, EmptyLocationRange) +func (v *StorageReferenceValue) StaticType(context ValueStaticTypeContext) StaticType { + referencedValue, err := v.dereference(context, EmptyLocationRange) if err != nil { panic(err) } @@ -107,9 +107,9 @@ func (v *StorageReferenceValue) StaticType(staticTypeGetter StaticTypeGetter) St self := *referencedValue return NewReferenceStaticType( - staticTypeGetter, + context, v.Authorization, - self.StaticType(staticTypeGetter), + self.StaticType(context), ) } @@ -121,14 +121,14 @@ func (*StorageReferenceValue) IsImportable(_ *Interpreter, _ LocationRange) bool return false } -func (v *StorageReferenceValue) dereference(staticTypeGetter StaticTypeGetter, locationRange LocationRange) (*Value, error) { +func (v *StorageReferenceValue) dereference(context ValueStaticTypeContext, locationRange LocationRange) (*Value, error) { address := v.TargetStorageAddress domain := v.TargetPath.Domain.StorageDomain() identifier := v.TargetPath.Identifier storageMapKey := StringStorageMapKey(identifier) - referenced := staticTypeGetter.ReadStored(address, domain, storageMapKey) + referenced := context.ReadStored(address, domain, storageMapKey) if referenced == nil { return nil, nil } @@ -141,10 +141,10 @@ func (v *StorageReferenceValue) dereference(staticTypeGetter StaticTypeGetter, l } if v.BorrowedType != nil { - staticType := referenced.StaticType(staticTypeGetter) + staticType := referenced.StaticType(context) - if !staticTypeGetter.IsSubTypeOfSemaType(staticType, v.BorrowedType) { - semaType := staticTypeGetter.MustConvertStaticToSemaType(staticType) + if !context.IsSubTypeOfSemaType(staticType, v.BorrowedType) { + semaType := context.MustConvertStaticToSemaType(staticType) return nil, ForceCastTypeMismatchError{ ExpectedType: v.BorrowedType, @@ -324,7 +324,7 @@ func (v *StorageReferenceValue) RemoveTypeKey( RemoveTypeKey(interpreter, locationRange, key) } -func (v *StorageReferenceValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v *StorageReferenceValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherReference, ok := other.(*StorageReferenceValue) if !ok || v.TargetStorageAddress != otherReference.TargetStorageAddress || diff --git a/interpreter/value_storagecapabilitycontroller.go b/interpreter/value_storagecapabilitycontroller.go index 4764c0d5bf..177482eb8c 100644 --- a/interpreter/value_storagecapabilitycontroller.go +++ b/interpreter/value_storagecapabilitycontroller.go @@ -118,7 +118,7 @@ func (v *StorageCapabilityControllerValue) Walk(_ *Interpreter, walkChild func(V walkChild(v.CapabilityID) } -func (v *StorageCapabilityControllerValue) StaticType(_ StaticTypeGetter) StaticType { +func (v *StorageCapabilityControllerValue) StaticType(_ ValueStaticTypeContext) StaticType { return PrimitiveStaticTypeStorageCapabilityController } @@ -160,7 +160,7 @@ func (v *StorageCapabilityControllerValue) ConformsToStaticType( return true } -func (v *StorageCapabilityControllerValue) Equal(context ComparisonContext, locationRange LocationRange, other Value) bool { +func (v *StorageCapabilityControllerValue) Equal(context ValueComparisonContext, locationRange LocationRange, other Value) bool { otherController, ok := other.(*StorageCapabilityControllerValue) if !ok { return false diff --git a/interpreter/value_string.go b/interpreter/value_string.go index 4e07286b57..68c6040966 100644 --- a/interpreter/value_string.go +++ b/interpreter/value_string.go @@ -121,8 +121,8 @@ func (*StringValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (*StringValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeString) +func (*StringValue) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeString) } func (*StringValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -143,7 +143,7 @@ func (v *StringValue) MeteredString(interpreter *Interpreter, _ SeenReferences, return v.String() } -func (v *StringValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v *StringValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherString, ok := other.(*StringValue) if !ok { return false @@ -151,7 +151,7 @@ func (v *StringValue) Equal(_ ComparisonContext, _ LocationRange, other Value) b return v.Str == otherString.Str } -func (v *StringValue) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v *StringValue) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ @@ -165,7 +165,7 @@ func (v *StringValue) Less(context ComparisonContext, other ComparableValue, loc return AsBoolValue(v.Str < otherString.Str) } -func (v *StringValue) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v *StringValue) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ @@ -179,7 +179,7 @@ func (v *StringValue) LessEqual(context ComparisonContext, other ComparableValue return AsBoolValue(v.Str <= otherString.Str) } -func (v *StringValue) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v *StringValue) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ @@ -193,7 +193,7 @@ func (v *StringValue) Greater(context ComparisonContext, other ComparableValue, return AsBoolValue(v.Str > otherString.Str) } -func (v *StringValue) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v *StringValue) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ diff --git a/interpreter/value_type.go b/interpreter/value_type.go index 24708c2ea3..9e09f41768 100644 --- a/interpreter/value_type.go +++ b/interpreter/value_type.go @@ -65,8 +65,8 @@ func (TypeValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (TypeValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeMetaType) +func (TypeValue) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeMetaType) } func (TypeValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -98,7 +98,7 @@ func (v TypeValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ L return format.TypeValue(typeString) } -func (v TypeValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v TypeValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherTypeValue, ok := other.(TypeValue) if !ok { return false diff --git a/interpreter/value_ufix64.go b/interpreter/value_ufix64.go index 52218ee1b6..56c0fee7b0 100644 --- a/interpreter/value_ufix64.go +++ b/interpreter/value_ufix64.go @@ -86,8 +86,8 @@ func (UFix64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UFix64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUFix64) +func (UFix64Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeUFix64) } func (UFix64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -116,11 +116,11 @@ func (v UFix64Value) ToInt(_ LocationRange) int { return int(v / sema.Fix64Factor) } -func (v UFix64Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v UFix64Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UFix64Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -138,7 +138,7 @@ func (v UFix64Value) Plus(context ArithmeticContext, other NumberValue, location return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -161,7 +161,7 @@ func (v UFix64Value) SaturatingPlus(context ArithmeticContext, other NumberValue return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -187,7 +187,7 @@ func (v UFix64Value) Minus(context ArithmeticContext, other NumberValue, locatio return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -211,7 +211,7 @@ func (v UFix64Value) SaturatingMinus(context ArithmeticContext, other NumberValu return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -241,7 +241,7 @@ func (v UFix64Value) Mul(context ArithmeticContext, other NumberValue, locationR return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -269,7 +269,7 @@ func (v UFix64Value) SaturatingMul(context ArithmeticContext, other NumberValue, return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -293,7 +293,7 @@ func (v UFix64Value) Div(context ArithmeticContext, other NumberValue, locationR return NewUFix64Value(context, valueGetter) } -func (v UFix64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -309,7 +309,7 @@ func (v UFix64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return v.Div(context, other, locationRange) } -func (v UFix64Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UFix64Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -345,7 +345,7 @@ func (v UFix64Value) Mod(context ArithmeticContext, other NumberValue, locationR ) } -func (v UFix64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UFix64Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -359,7 +359,7 @@ func (v UFix64Value) Less(context ComparisonContext, other ComparableValue, loca return AsBoolValue(v < o) } -func (v UFix64Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UFix64Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -373,7 +373,7 @@ func (v UFix64Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v UFix64Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UFix64Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -387,7 +387,7 @@ func (v UFix64Value) Greater(context ComparisonContext, other ComparableValue, l return AsBoolValue(v > o) } -func (v UFix64Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UFix64Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ @@ -401,7 +401,7 @@ func (v UFix64Value) GreaterEqual(context ComparisonContext, other ComparableVal return AsBoolValue(v >= o) } -func (v UFix64Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v UFix64Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherUFix64, ok := other.(UFix64Value) if !ok { return false diff --git a/interpreter/value_uint.go b/interpreter/value_uint.go index f85dc6bcae..4811ed2033 100644 --- a/interpreter/value_uint.go +++ b/interpreter/value_uint.go @@ -124,8 +124,8 @@ func (UIntValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UIntValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt) +func (UIntValue) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeUInt) } func (v UIntValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -168,11 +168,11 @@ func (v UIntValue) MeteredString(interpreter *Interpreter, _ SeenReferences, _ L return v.String() } -func (v UIntValue) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v UIntValue) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UIntValue) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ @@ -193,7 +193,7 @@ func (v UIntValue) Plus(context ArithmeticContext, other NumberValue, locationRa ) } -func (v UIntValue) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -209,7 +209,7 @@ func (v UIntValue) SaturatingPlus(context ArithmeticContext, other NumberValue, return v.Plus(context, other, locationRange) } -func (v UIntValue) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ @@ -237,7 +237,7 @@ func (v UIntValue) Minus(context ArithmeticContext, other NumberValue, locationR ) } -func (v UIntValue) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ @@ -263,7 +263,7 @@ func (v UIntValue) SaturatingMinus(context ArithmeticContext, other NumberValue, ) } -func (v UIntValue) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ @@ -291,7 +291,7 @@ func (v UIntValue) Mod(context ArithmeticContext, other NumberValue, locationRan ) } -func (v UIntValue) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ @@ -312,7 +312,7 @@ func (v UIntValue) Mul(context ArithmeticContext, other NumberValue, locationRan ) } -func (v UIntValue) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -328,7 +328,7 @@ func (v UIntValue) SaturatingMul(context ArithmeticContext, other NumberValue, l return v.Mul(context, other, locationRange) } -func (v UIntValue) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ @@ -355,7 +355,7 @@ func (v UIntValue) Div(context ArithmeticContext, other NumberValue, locationRan ) } -func (v UIntValue) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UIntValue) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -371,7 +371,7 @@ func (v UIntValue) SaturatingDiv(context ArithmeticContext, other NumberValue, l return v.Div(context, other, locationRange) } -func (v UIntValue) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UIntValue) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ @@ -386,7 +386,7 @@ func (v UIntValue) Less(context ComparisonContext, other ComparableValue, locati return AsBoolValue(cmp == -1) } -func (v UIntValue) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UIntValue) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ @@ -401,7 +401,7 @@ func (v UIntValue) LessEqual(context ComparisonContext, other ComparableValue, l return AsBoolValue(cmp <= 0) } -func (v UIntValue) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UIntValue) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ @@ -416,7 +416,7 @@ func (v UIntValue) Greater(context ComparisonContext, other ComparableValue, loc return AsBoolValue(cmp == 1) } -func (v UIntValue) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UIntValue) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ @@ -431,7 +431,7 @@ func (v UIntValue) GreaterEqual(context ComparisonContext, other ComparableValue return AsBoolValue(cmp >= 0) } -func (v UIntValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v UIntValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherUInt, ok := other.(UIntValue) if !ok { return false diff --git a/interpreter/value_uint128.go b/interpreter/value_uint128.go index 9fd90ad772..a7b52041db 100644 --- a/interpreter/value_uint128.go +++ b/interpreter/value_uint128.go @@ -82,8 +82,8 @@ func (UInt128Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt128Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt128) +func (UInt128Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeUInt128) } func (UInt128Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -126,11 +126,11 @@ func (v UInt128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, return v.String() } -func (v UInt128Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v UInt128Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UInt128Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -166,7 +166,7 @@ func (v UInt128Value) Plus(context ArithmeticContext, other NumberValue, locatio ) } -func (v UInt128Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -200,7 +200,7 @@ func (v UInt128Value) SaturatingPlus(context ArithmeticContext, other NumberValu ) } -func (v UInt128Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -236,7 +236,7 @@ func (v UInt128Value) Minus(context ArithmeticContext, other NumberValue, locati ) } -func (v UInt128Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -270,7 +270,7 @@ func (v UInt128Value) SaturatingMinus(context ArithmeticContext, other NumberVal ) } -func (v UInt128Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -295,7 +295,7 @@ func (v UInt128Value) Mod(context ArithmeticContext, other NumberValue, location ) } -func (v UInt128Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -321,7 +321,7 @@ func (v UInt128Value) Mul(context ArithmeticContext, other NumberValue, location ) } -func (v UInt128Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -345,7 +345,7 @@ func (v UInt128Value) SaturatingMul(context ArithmeticContext, other NumberValue ) } -func (v UInt128Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -371,7 +371,7 @@ func (v UInt128Value) Div(context ArithmeticContext, other NumberValue, location } -func (v UInt128Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt128Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -387,7 +387,7 @@ func (v UInt128Value) SaturatingDiv(context ArithmeticContext, other NumberValue return v.Div(context, other, locationRange) } -func (v UInt128Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt128Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -402,7 +402,7 @@ func (v UInt128Value) Less(context ComparisonContext, other ComparableValue, loc return AsBoolValue(cmp == -1) } -func (v UInt128Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt128Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -417,7 +417,7 @@ func (v UInt128Value) LessEqual(context ComparisonContext, other ComparableValue return AsBoolValue(cmp <= 0) } -func (v UInt128Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt128Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -432,7 +432,7 @@ func (v UInt128Value) Greater(context ComparisonContext, other ComparableValue, return AsBoolValue(cmp == 1) } -func (v UInt128Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt128Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ @@ -447,7 +447,7 @@ func (v UInt128Value) GreaterEqual(context ComparisonContext, other ComparableVa return AsBoolValue(cmp >= 0) } -func (v UInt128Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v UInt128Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(UInt128Value) if !ok { return false diff --git a/interpreter/value_uint16.go b/interpreter/value_uint16.go index 1ff066c8c0..eae72ff20f 100644 --- a/interpreter/value_uint16.go +++ b/interpreter/value_uint16.go @@ -67,8 +67,8 @@ func (UInt16Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt16Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt16) +func (UInt16Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeUInt16) } func (UInt16Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -96,11 +96,11 @@ func (v UInt16Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ func (v UInt16Value) ToInt(_ LocationRange) int { return int(v) } -func (v UInt16Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v UInt16Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UInt16Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -126,7 +126,7 @@ func (v UInt16Value) Plus(context ArithmeticContext, other NumberValue, location ) } -func (v UInt16Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -150,7 +150,7 @@ func (v UInt16Value) SaturatingPlus(context ArithmeticContext, other NumberValue ) } -func (v UInt16Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -176,7 +176,7 @@ func (v UInt16Value) Minus(context ArithmeticContext, other NumberValue, locatio ) } -func (v UInt16Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -200,7 +200,7 @@ func (v UInt16Value) SaturatingMinus(context ArithmeticContext, other NumberValu ) } -func (v UInt16Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -224,7 +224,7 @@ func (v UInt16Value) Mod(context ArithmeticContext, other NumberValue, locationR ) } -func (v UInt16Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -249,7 +249,7 @@ func (v UInt16Value) Mul(context ArithmeticContext, other NumberValue, locationR ) } -func (v UInt16Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -272,7 +272,7 @@ func (v UInt16Value) SaturatingMul(context ArithmeticContext, other NumberValue, ) } -func (v UInt16Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -296,7 +296,7 @@ func (v UInt16Value) Div(context ArithmeticContext, other NumberValue, locationR ) } -func (v UInt16Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt16Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -312,7 +312,7 @@ func (v UInt16Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return v.Div(context, other, locationRange) } -func (v UInt16Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt16Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -326,7 +326,7 @@ func (v UInt16Value) Less(context ComparisonContext, other ComparableValue, loca return AsBoolValue(v < o) } -func (v UInt16Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt16Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -340,7 +340,7 @@ func (v UInt16Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v UInt16Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt16Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -354,7 +354,7 @@ func (v UInt16Value) Greater(context ComparisonContext, other ComparableValue, l return AsBoolValue(v > o) } -func (v UInt16Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt16Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ @@ -368,7 +368,7 @@ func (v UInt16Value) GreaterEqual(context ComparisonContext, other ComparableVal return AsBoolValue(v >= o) } -func (v UInt16Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v UInt16Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherUInt16, ok := other.(UInt16Value) if !ok { return false diff --git a/interpreter/value_uint256.go b/interpreter/value_uint256.go index 0643fc1787..5553c7b8d2 100644 --- a/interpreter/value_uint256.go +++ b/interpreter/value_uint256.go @@ -82,8 +82,8 @@ func (UInt256Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt256Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt256) +func (UInt256Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeUInt256) } func (UInt256Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -127,11 +127,11 @@ func (v UInt256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, return v.String() } -func (v UInt256Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v UInt256Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UInt256Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -168,7 +168,7 @@ func (v UInt256Value) Plus(context ArithmeticContext, other NumberValue, locatio } -func (v UInt256Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -202,7 +202,7 @@ func (v UInt256Value) SaturatingPlus(context ArithmeticContext, other NumberValu ) } -func (v UInt256Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -238,7 +238,7 @@ func (v UInt256Value) Minus(context ArithmeticContext, other NumberValue, locati ) } -func (v UInt256Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -273,7 +273,7 @@ func (v UInt256Value) SaturatingMinus(context ArithmeticContext, other NumberVal } -func (v UInt256Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -298,7 +298,7 @@ func (v UInt256Value) Mod(context ArithmeticContext, other NumberValue, location ) } -func (v UInt256Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -324,7 +324,7 @@ func (v UInt256Value) Mul(context ArithmeticContext, other NumberValue, location ) } -func (v UInt256Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -348,7 +348,7 @@ func (v UInt256Value) SaturatingMul(context ArithmeticContext, other NumberValue ) } -func (v UInt256Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -373,7 +373,7 @@ func (v UInt256Value) Div(context ArithmeticContext, other NumberValue, location ) } -func (v UInt256Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt256Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -389,7 +389,7 @@ func (v UInt256Value) SaturatingDiv(context ArithmeticContext, other NumberValue return v.Div(context, other, locationRange) } -func (v UInt256Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt256Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -404,7 +404,7 @@ func (v UInt256Value) Less(context ComparisonContext, other ComparableValue, loc return AsBoolValue(cmp == -1) } -func (v UInt256Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt256Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -419,7 +419,7 @@ func (v UInt256Value) LessEqual(context ComparisonContext, other ComparableValue return AsBoolValue(cmp <= 0) } -func (v UInt256Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt256Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -434,7 +434,7 @@ func (v UInt256Value) Greater(context ComparisonContext, other ComparableValue, return AsBoolValue(cmp == 1) } -func (v UInt256Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt256Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ @@ -449,7 +449,7 @@ func (v UInt256Value) GreaterEqual(context ComparisonContext, other ComparableVa return AsBoolValue(cmp >= 0) } -func (v UInt256Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v UInt256Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(UInt256Value) if !ok { return false diff --git a/interpreter/value_uint32.go b/interpreter/value_uint32.go index 8923b16548..47bbbea382 100644 --- a/interpreter/value_uint32.go +++ b/interpreter/value_uint32.go @@ -67,8 +67,8 @@ func (UInt32Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt32Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt32) +func (UInt32Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeUInt32) } func (UInt32Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -97,11 +97,11 @@ func (v UInt32Value) ToInt(_ LocationRange) int { return int(v) } -func (v UInt32Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v UInt32Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UInt32Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -127,7 +127,7 @@ func (v UInt32Value) Plus(context ArithmeticContext, other NumberValue, location ) } -func (v UInt32Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -151,7 +151,7 @@ func (v UInt32Value) SaturatingPlus(context ArithmeticContext, other NumberValue ) } -func (v UInt32Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -177,7 +177,7 @@ func (v UInt32Value) Minus(context ArithmeticContext, other NumberValue, locatio ) } -func (v UInt32Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -201,7 +201,7 @@ func (v UInt32Value) SaturatingMinus(context ArithmeticContext, other NumberValu ) } -func (v UInt32Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -225,7 +225,7 @@ func (v UInt32Value) Mod(context ArithmeticContext, other NumberValue, locationR ) } -func (v UInt32Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -249,7 +249,7 @@ func (v UInt32Value) Mul(context ArithmeticContext, other NumberValue, locationR ) } -func (v UInt32Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -273,7 +273,7 @@ func (v UInt32Value) SaturatingMul(context ArithmeticContext, other NumberValue, ) } -func (v UInt32Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -297,7 +297,7 @@ func (v UInt32Value) Div(context ArithmeticContext, other NumberValue, locationR ) } -func (v UInt32Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt32Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -313,7 +313,7 @@ func (v UInt32Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return v.Div(context, other, locationRange) } -func (v UInt32Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt32Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -327,7 +327,7 @@ func (v UInt32Value) Less(context ComparisonContext, other ComparableValue, loca return AsBoolValue(v < o) } -func (v UInt32Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt32Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -341,7 +341,7 @@ func (v UInt32Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v UInt32Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt32Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -355,7 +355,7 @@ func (v UInt32Value) Greater(context ComparisonContext, other ComparableValue, l return AsBoolValue(v > o) } -func (v UInt32Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt32Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ @@ -369,7 +369,7 @@ func (v UInt32Value) GreaterEqual(context ComparisonContext, other ComparableVal return AsBoolValue(v >= o) } -func (v UInt32Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v UInt32Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherUInt32, ok := other.(UInt32Value) if !ok { return false diff --git a/interpreter/value_uint64.go b/interpreter/value_uint64.go index 9e34eca4cf..705865caaa 100644 --- a/interpreter/value_uint64.go +++ b/interpreter/value_uint64.go @@ -74,8 +74,8 @@ func (UInt64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt64) +func (UInt64Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeUInt64) } func (UInt64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -124,7 +124,7 @@ func (v UInt64Value) ToBigInt(memoryGauge common.MemoryGauge) *big.Int { return new(big.Int).SetUint64(uint64(v)) } -func (v UInt64Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v UInt64Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } @@ -139,7 +139,7 @@ func safeAddUint64(a, b uint64, locationRange LocationRange) uint64 { return sum } -func (v UInt64Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -158,7 +158,7 @@ func (v UInt64Value) Plus(context ArithmeticContext, other NumberValue, location ) } -func (v UInt64Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -182,7 +182,7 @@ func (v UInt64Value) SaturatingPlus(context ArithmeticContext, other NumberValue ) } -func (v UInt64Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -208,7 +208,7 @@ func (v UInt64Value) Minus(context ArithmeticContext, other NumberValue, locatio ) } -func (v UInt64Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -232,7 +232,7 @@ func (v UInt64Value) SaturatingMinus(context ArithmeticContext, other NumberValu ) } -func (v UInt64Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -256,7 +256,7 @@ func (v UInt64Value) Mod(context ArithmeticContext, other NumberValue, locationR ) } -func (v UInt64Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -280,7 +280,7 @@ func (v UInt64Value) Mul(context ArithmeticContext, other NumberValue, locationR ) } -func (v UInt64Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -303,7 +303,7 @@ func (v UInt64Value) SaturatingMul(context ArithmeticContext, other NumberValue, ) } -func (v UInt64Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -327,7 +327,7 @@ func (v UInt64Value) Div(context ArithmeticContext, other NumberValue, locationR ) } -func (v UInt64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt64Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -343,7 +343,7 @@ func (v UInt64Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return v.Div(context, other, locationRange) } -func (v UInt64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt64Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -357,7 +357,7 @@ func (v UInt64Value) Less(context ComparisonContext, other ComparableValue, loca return AsBoolValue(v < o) } -func (v UInt64Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt64Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -371,7 +371,7 @@ func (v UInt64Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v UInt64Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt64Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -385,7 +385,7 @@ func (v UInt64Value) Greater(context ComparisonContext, other ComparableValue, l return AsBoolValue(v > o) } -func (v UInt64Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt64Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ @@ -399,7 +399,7 @@ func (v UInt64Value) GreaterEqual(context ComparisonContext, other ComparableVal return AsBoolValue(v >= o) } -func (v UInt64Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v UInt64Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherUInt64, ok := other.(UInt64Value) if !ok { return false diff --git a/interpreter/value_uint8.go b/interpreter/value_uint8.go index 5080df6887..13861bdc9e 100644 --- a/interpreter/value_uint8.go +++ b/interpreter/value_uint8.go @@ -67,8 +67,8 @@ func (UInt8Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (UInt8Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeUInt8) +func (UInt8Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeUInt8) } func (UInt8Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -97,11 +97,11 @@ func (v UInt8Value) ToInt(_ LocationRange) int { return int(v) } -func (v UInt8Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v UInt8Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v UInt8Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -124,7 +124,7 @@ func (v UInt8Value) Plus(context ArithmeticContext, other NumberValue, locationR }) } -func (v UInt8Value) SaturatingPlus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) SaturatingPlus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -145,7 +145,7 @@ func (v UInt8Value) SaturatingPlus(context ArithmeticContext, other NumberValue, }) } -func (v UInt8Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -171,7 +171,7 @@ func (v UInt8Value) Minus(context ArithmeticContext, other NumberValue, location ) } -func (v UInt8Value) SaturatingMinus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) SaturatingMinus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -195,7 +195,7 @@ func (v UInt8Value) SaturatingMinus(context ArithmeticContext, other NumberValue ) } -func (v UInt8Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -219,7 +219,7 @@ func (v UInt8Value) Mod(context ArithmeticContext, other NumberValue, locationRa ) } -func (v UInt8Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -244,7 +244,7 @@ func (v UInt8Value) Mul(context ArithmeticContext, other NumberValue, locationRa ) } -func (v UInt8Value) SaturatingMul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) SaturatingMul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -267,7 +267,7 @@ func (v UInt8Value) SaturatingMul(context ArithmeticContext, other NumberValue, ) } -func (v UInt8Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -291,7 +291,7 @@ func (v UInt8Value) Div(context ArithmeticContext, other NumberValue, locationRa ) } -func (v UInt8Value) SaturatingDiv(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v UInt8Value) SaturatingDiv(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { defer func() { r := recover() if _, ok := r.(InvalidOperandsError); ok { @@ -307,7 +307,7 @@ func (v UInt8Value) SaturatingDiv(context ArithmeticContext, other NumberValue, return v.Div(context, other, locationRange) } -func (v UInt8Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt8Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -321,7 +321,7 @@ func (v UInt8Value) Less(context ComparisonContext, other ComparableValue, locat return AsBoolValue(v < o) } -func (v UInt8Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt8Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -335,7 +335,7 @@ func (v UInt8Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v UInt8Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt8Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -349,7 +349,7 @@ func (v UInt8Value) Greater(context ComparisonContext, other ComparableValue, lo return AsBoolValue(v > o) } -func (v UInt8Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v UInt8Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ @@ -363,7 +363,7 @@ func (v UInt8Value) GreaterEqual(context ComparisonContext, other ComparableValu return AsBoolValue(v >= o) } -func (v UInt8Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v UInt8Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherUInt8, ok := other.(UInt8Value) if !ok { return false diff --git a/interpreter/value_void.go b/interpreter/value_void.go index d7ebc5dc56..44faf55187 100644 --- a/interpreter/value_void.go +++ b/interpreter/value_void.go @@ -47,8 +47,8 @@ func (VoidValue) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (VoidValue) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeVoid) +func (VoidValue) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeVoid) } func (VoidValue) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -76,7 +76,7 @@ func (v VoidValue) ConformsToStaticType( return true } -func (v VoidValue) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v VoidValue) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { _, ok := other.(VoidValue) return ok } diff --git a/interpreter/value_word128.go b/interpreter/value_word128.go index b11482a8d7..a810ba7457 100644 --- a/interpreter/value_word128.go +++ b/interpreter/value_word128.go @@ -82,8 +82,8 @@ func (Word128Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word128Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord128) +func (Word128Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeWord128) } func (Word128Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -126,11 +126,11 @@ func (v Word128Value) MeteredString(interpreter *Interpreter, _ SeenReferences, return v.String() } -func (v Word128Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v Word128Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word128Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ @@ -168,11 +168,11 @@ func (v Word128Value) Plus(context ArithmeticContext, other NumberValue, locatio ) } -func (v Word128Value) SaturatingPlus(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { +func (v Word128Value) SaturatingPlus(_ NumberValueArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word128Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ @@ -210,11 +210,11 @@ func (v Word128Value) Minus(context ArithmeticContext, other NumberValue, locati ) } -func (v Word128Value) SaturatingMinus(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { +func (v Word128Value) SaturatingMinus(_ NumberValueArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word128Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ @@ -239,7 +239,7 @@ func (v Word128Value) Mod(context ArithmeticContext, other NumberValue, location ) } -func (v Word128Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ @@ -263,11 +263,11 @@ func (v Word128Value) Mul(context ArithmeticContext, other NumberValue, location ) } -func (v Word128Value) SaturatingMul(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { +func (v Word128Value) SaturatingMul(_ NumberValueArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word128Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ @@ -293,11 +293,11 @@ func (v Word128Value) Div(context ArithmeticContext, other NumberValue, location } -func (v Word128Value) SaturatingDiv(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { +func (v Word128Value) SaturatingDiv(_ NumberValueArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word128Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word128Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ @@ -312,7 +312,7 @@ func (v Word128Value) Less(context ComparisonContext, other ComparableValue, loc return AsBoolValue(cmp == -1) } -func (v Word128Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word128Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ @@ -327,7 +327,7 @@ func (v Word128Value) LessEqual(context ComparisonContext, other ComparableValue return AsBoolValue(cmp <= 0) } -func (v Word128Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word128Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ @@ -342,7 +342,7 @@ func (v Word128Value) Greater(context ComparisonContext, other ComparableValue, return AsBoolValue(cmp == 1) } -func (v Word128Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word128Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ @@ -357,7 +357,7 @@ func (v Word128Value) GreaterEqual(context ComparisonContext, other ComparableVa return AsBoolValue(cmp >= 0) } -func (v Word128Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Word128Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(Word128Value) if !ok { return false diff --git a/interpreter/value_word16.go b/interpreter/value_word16.go index d4e14009a5..9c72165a50 100644 --- a/interpreter/value_word16.go +++ b/interpreter/value_word16.go @@ -68,8 +68,8 @@ func (Word16Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word16Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord16) +func (Word16Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeWord16) } func (Word16Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -97,11 +97,11 @@ func (v Word16Value) MeteredString(interpreter *Interpreter, _ SeenReferences, _ func (v Word16Value) ToInt(_ LocationRange) int { return int(v) } -func (v Word16Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v Word16Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word16Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word16Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ @@ -119,11 +119,11 @@ func (v Word16Value) Plus(context ArithmeticContext, other NumberValue, location return NewWord16Value(context, valueGetter) } -func (v Word16Value) SaturatingPlus(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word16Value) SaturatingPlus(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word16Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word16Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ @@ -141,11 +141,11 @@ func (v Word16Value) Minus(context ArithmeticContext, other NumberValue, locatio return NewWord16Value(context, valueGetter) } -func (v Word16Value) SaturatingMinus(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word16Value) SaturatingMinus(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word16Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word16Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ @@ -169,7 +169,7 @@ func (v Word16Value) Mod(context ArithmeticContext, other NumberValue, locationR return NewWord16Value(context, valueGetter) } -func (v Word16Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word16Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ @@ -187,11 +187,11 @@ func (v Word16Value) Mul(context ArithmeticContext, other NumberValue, locationR return NewWord16Value(context, valueGetter) } -func (v Word16Value) SaturatingMul(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word16Value) SaturatingMul(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word16Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word16Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ @@ -215,11 +215,11 @@ func (v Word16Value) Div(context ArithmeticContext, other NumberValue, locationR return NewWord16Value(context, valueGetter) } -func (v Word16Value) SaturatingDiv(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word16Value) SaturatingDiv(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word16Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word16Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ @@ -233,7 +233,7 @@ func (v Word16Value) Less(context ComparisonContext, other ComparableValue, loca return AsBoolValue(v < o) } -func (v Word16Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word16Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ @@ -247,7 +247,7 @@ func (v Word16Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v Word16Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word16Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ @@ -261,7 +261,7 @@ func (v Word16Value) Greater(context ComparisonContext, other ComparableValue, l return AsBoolValue(v > o) } -func (v Word16Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word16Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ @@ -275,7 +275,7 @@ func (v Word16Value) GreaterEqual(context ComparisonContext, other ComparableVal return AsBoolValue(v >= o) } -func (v Word16Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Word16Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherWord16, ok := other.(Word16Value) if !ok { return false diff --git a/interpreter/value_word256.go b/interpreter/value_word256.go index 4bffb20f30..4411470d94 100644 --- a/interpreter/value_word256.go +++ b/interpreter/value_word256.go @@ -82,8 +82,8 @@ func (Word256Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word256Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord256) +func (Word256Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeWord256) } func (Word256Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -126,11 +126,11 @@ func (v Word256Value) MeteredString(interpreter *Interpreter, _ SeenReferences, return v.String() } -func (v Word256Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v Word256Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word256Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ @@ -168,11 +168,11 @@ func (v Word256Value) Plus(context ArithmeticContext, other NumberValue, locatio ) } -func (v Word256Value) SaturatingPlus(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { +func (v Word256Value) SaturatingPlus(_ NumberValueArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word256Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ @@ -210,11 +210,11 @@ func (v Word256Value) Minus(context ArithmeticContext, other NumberValue, locati ) } -func (v Word256Value) SaturatingMinus(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { +func (v Word256Value) SaturatingMinus(_ NumberValueArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word256Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ @@ -239,7 +239,7 @@ func (v Word256Value) Mod(context ArithmeticContext, other NumberValue, location ) } -func (v Word256Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ @@ -263,11 +263,11 @@ func (v Word256Value) Mul(context ArithmeticContext, other NumberValue, location ) } -func (v Word256Value) SaturatingMul(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { +func (v Word256Value) SaturatingMul(_ NumberValueArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word256Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ @@ -293,11 +293,11 @@ func (v Word256Value) Div(context ArithmeticContext, other NumberValue, location } -func (v Word256Value) SaturatingDiv(_ ArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { +func (v Word256Value) SaturatingDiv(_ NumberValueArithmeticContext, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word256Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word256Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ @@ -312,7 +312,7 @@ func (v Word256Value) Less(context ComparisonContext, other ComparableValue, loc return AsBoolValue(cmp == -1) } -func (v Word256Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word256Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ @@ -327,7 +327,7 @@ func (v Word256Value) LessEqual(context ComparisonContext, other ComparableValue return AsBoolValue(cmp <= 0) } -func (v Word256Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word256Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ @@ -342,7 +342,7 @@ func (v Word256Value) Greater(context ComparisonContext, other ComparableValue, return AsBoolValue(cmp == 1) } -func (v Word256Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word256Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ @@ -357,7 +357,7 @@ func (v Word256Value) GreaterEqual(context ComparisonContext, other ComparableVa return AsBoolValue(cmp >= 0) } -func (v Word256Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Word256Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherInt, ok := other.(Word256Value) if !ok { return false diff --git a/interpreter/value_word32.go b/interpreter/value_word32.go index 805bdabe11..cd11bc5c17 100644 --- a/interpreter/value_word32.go +++ b/interpreter/value_word32.go @@ -68,8 +68,8 @@ func (Word32Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word32Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord32) +func (Word32Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeWord32) } func (Word32Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -98,11 +98,11 @@ func (v Word32Value) ToInt(_ LocationRange) int { return int(v) } -func (v Word32Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v Word32Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word32Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word32Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ @@ -120,11 +120,11 @@ func (v Word32Value) Plus(context ArithmeticContext, other NumberValue, location return NewWord32Value(context, valueGetter) } -func (v Word32Value) SaturatingPlus(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word32Value) SaturatingPlus(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word32Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word32Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ @@ -142,11 +142,11 @@ func (v Word32Value) Minus(context ArithmeticContext, other NumberValue, locatio return NewWord32Value(context, valueGetter) } -func (v Word32Value) SaturatingMinus(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word32Value) SaturatingMinus(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word32Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word32Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ @@ -170,7 +170,7 @@ func (v Word32Value) Mod(context ArithmeticContext, other NumberValue, locationR return NewWord32Value(context, valueGetter) } -func (v Word32Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word32Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ @@ -188,11 +188,11 @@ func (v Word32Value) Mul(context ArithmeticContext, other NumberValue, locationR return NewWord32Value(context, valueGetter) } -func (v Word32Value) SaturatingMul(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word32Value) SaturatingMul(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word32Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word32Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ @@ -216,11 +216,11 @@ func (v Word32Value) Div(context ArithmeticContext, other NumberValue, locationR return NewWord32Value(context, valueGetter) } -func (v Word32Value) SaturatingDiv(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word32Value) SaturatingDiv(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word32Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word32Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ @@ -234,7 +234,7 @@ func (v Word32Value) Less(context ComparisonContext, other ComparableValue, loca return AsBoolValue(v < o) } -func (v Word32Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word32Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ @@ -248,7 +248,7 @@ func (v Word32Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v Word32Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word32Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ @@ -262,7 +262,7 @@ func (v Word32Value) Greater(context ComparisonContext, other ComparableValue, l return AsBoolValue(v > o) } -func (v Word32Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word32Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ @@ -276,7 +276,7 @@ func (v Word32Value) GreaterEqual(context ComparisonContext, other ComparableVal return AsBoolValue(v >= o) } -func (v Word32Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Word32Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherWord32, ok := other.(Word32Value) if !ok { return false diff --git a/interpreter/value_word64.go b/interpreter/value_word64.go index 0cfbfef2a2..8beb22cccf 100644 --- a/interpreter/value_word64.go +++ b/interpreter/value_word64.go @@ -76,8 +76,8 @@ func (Word64Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word64Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord64) +func (Word64Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeWord64) } func (Word64Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -126,11 +126,11 @@ func (v Word64Value) ToBigInt(memoryGauge common.MemoryGauge) *big.Int { return new(big.Int).SetUint64(uint64(v)) } -func (v Word64Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v Word64Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word64Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word64Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ @@ -148,11 +148,11 @@ func (v Word64Value) Plus(context ArithmeticContext, other NumberValue, location return NewWord64Value(context, valueGetter) } -func (v Word64Value) SaturatingPlus(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word64Value) SaturatingPlus(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word64Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word64Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ @@ -170,11 +170,11 @@ func (v Word64Value) Minus(context ArithmeticContext, other NumberValue, locatio return NewWord64Value(context, valueGetter) } -func (v Word64Value) SaturatingMinus(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word64Value) SaturatingMinus(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word64Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word64Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ @@ -198,7 +198,7 @@ func (v Word64Value) Mod(context ArithmeticContext, other NumberValue, locationR return NewWord64Value(context, valueGetter) } -func (v Word64Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word64Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ @@ -216,11 +216,11 @@ func (v Word64Value) Mul(context ArithmeticContext, other NumberValue, locationR return NewWord64Value(context, valueGetter) } -func (v Word64Value) SaturatingMul(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word64Value) SaturatingMul(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word64Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word64Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ @@ -244,11 +244,11 @@ func (v Word64Value) Div(context ArithmeticContext, other NumberValue, locationR return NewWord64Value(context, valueGetter) } -func (v Word64Value) SaturatingDiv(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word64Value) SaturatingDiv(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word64Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word64Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ @@ -262,7 +262,7 @@ func (v Word64Value) Less(context ComparisonContext, other ComparableValue, loca return AsBoolValue(v < o) } -func (v Word64Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word64Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ @@ -276,7 +276,7 @@ func (v Word64Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v Word64Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word64Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ @@ -290,7 +290,7 @@ func (v Word64Value) Greater(context ComparisonContext, other ComparableValue, l return AsBoolValue(v > o) } -func (v Word64Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word64Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ @@ -304,7 +304,7 @@ func (v Word64Value) GreaterEqual(context ComparisonContext, other ComparableVal return AsBoolValue(v >= o) } -func (v Word64Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Word64Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherWord64, ok := other.(Word64Value) if !ok { return false diff --git a/interpreter/value_word8.go b/interpreter/value_word8.go index 354a0e536c..90a8cfcd4b 100644 --- a/interpreter/value_word8.go +++ b/interpreter/value_word8.go @@ -67,8 +67,8 @@ func (Word8Value) Walk(_ *Interpreter, _ func(Value), _ LocationRange) { // NO-OP } -func (Word8Value) StaticType(staticTypeGetter StaticTypeGetter) StaticType { - return NewPrimitiveStaticType(staticTypeGetter, PrimitiveStaticTypeWord8) +func (Word8Value) StaticType(context ValueStaticTypeContext) StaticType { + return NewPrimitiveStaticType(context, PrimitiveStaticTypeWord8) } func (Word8Value) IsImportable(_ *Interpreter, _ LocationRange) bool { @@ -97,11 +97,11 @@ func (v Word8Value) ToInt(_ LocationRange) int { return int(v) } -func (v Word8Value) Negate(ArithmeticContext, LocationRange) NumberValue { +func (v Word8Value) Negate(NumberValueArithmeticContext, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word8Value) Plus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word8Value) Plus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ @@ -119,11 +119,11 @@ func (v Word8Value) Plus(context ArithmeticContext, other NumberValue, locationR return NewWord8Value(context, valueGetter) } -func (v Word8Value) SaturatingPlus(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word8Value) SaturatingPlus(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word8Value) Minus(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word8Value) Minus(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ @@ -141,11 +141,11 @@ func (v Word8Value) Minus(context ArithmeticContext, other NumberValue, location return NewWord8Value(context, valueGetter) } -func (v Word8Value) SaturatingMinus(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word8Value) SaturatingMinus(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word8Value) Mod(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word8Value) Mod(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ @@ -169,7 +169,7 @@ func (v Word8Value) Mod(context ArithmeticContext, other NumberValue, locationRa return NewWord8Value(context, valueGetter) } -func (v Word8Value) Mul(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word8Value) Mul(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ @@ -187,11 +187,11 @@ func (v Word8Value) Mul(context ArithmeticContext, other NumberValue, locationRa return NewWord8Value(context, valueGetter) } -func (v Word8Value) SaturatingMul(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word8Value) SaturatingMul(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word8Value) Div(context ArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word8Value) Div(context NumberValueArithmeticContext, other NumberValue, locationRange LocationRange) NumberValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ @@ -215,11 +215,11 @@ func (v Word8Value) Div(context ArithmeticContext, other NumberValue, locationRa return NewWord8Value(context, valueGetter) } -func (v Word8Value) SaturatingDiv(ArithmeticContext, NumberValue, LocationRange) NumberValue { +func (v Word8Value) SaturatingDiv(NumberValueArithmeticContext, NumberValue, LocationRange) NumberValue { panic(errors.NewUnreachableError()) } -func (v Word8Value) Less(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word8Value) Less(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ @@ -233,7 +233,7 @@ func (v Word8Value) Less(context ComparisonContext, other ComparableValue, locat return AsBoolValue(v < o) } -func (v Word8Value) LessEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word8Value) LessEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ @@ -247,7 +247,7 @@ func (v Word8Value) LessEqual(context ComparisonContext, other ComparableValue, return AsBoolValue(v <= o) } -func (v Word8Value) Greater(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word8Value) Greater(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ @@ -261,7 +261,7 @@ func (v Word8Value) Greater(context ComparisonContext, other ComparableValue, lo return AsBoolValue(v > o) } -func (v Word8Value) GreaterEqual(context ComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { +func (v Word8Value) GreaterEqual(context ValueComparisonContext, other ComparableValue, locationRange LocationRange) BoolValue { o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ @@ -275,7 +275,7 @@ func (v Word8Value) GreaterEqual(context ComparisonContext, other ComparableValu return AsBoolValue(v >= o) } -func (v Word8Value) Equal(_ ComparisonContext, _ LocationRange, other Value) bool { +func (v Word8Value) Equal(_ ValueComparisonContext, _ LocationRange, other Value) bool { otherWord8, ok := other.(Word8Value) if !ok { return false From bb0c5fa5942abf726188b367c699d32d8d147580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 2 Dec 2024 15:53:20 -0800 Subject: [PATCH 7/8] decouple iterator iteration from Interpreter --- interpreter/inclusive_range_iterator.go | 8 ++++---- interpreter/value.go | 7 ++++++- interpreter/value_array.go | 4 ++-- interpreter/value_string.go | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/interpreter/inclusive_range_iterator.go b/interpreter/inclusive_range_iterator.go index 0e6cbe8133..a3dc64027c 100644 --- a/interpreter/inclusive_range_iterator.go +++ b/interpreter/inclusive_range_iterator.go @@ -64,18 +64,18 @@ func NewInclusiveRangeIterator( } } -func (i *InclusiveRangeIterator) Next(interpreter *Interpreter, locationRange LocationRange) Value { +func (i *InclusiveRangeIterator) Next(context ValueIteratorContext, locationRange LocationRange) Value { valueToReturn := i.next // Ensure that valueToReturn is within the bounds. - if i.stepNegative && bool(valueToReturn.Less(interpreter, i.end, locationRange)) { + if i.stepNegative && bool(valueToReturn.Less(context, i.end, locationRange)) { return nil - } else if !i.stepNegative && bool(valueToReturn.Greater(interpreter, i.end, locationRange)) { + } else if !i.stepNegative && bool(valueToReturn.Greater(context, i.end, locationRange)) { return nil } // Update the next value. - nextValueToReturn, ok := valueToReturn.Plus(interpreter, i.step, locationRange).(IntegerValue) + nextValueToReturn, ok := valueToReturn.Plus(context, i.step, locationRange).(IntegerValue) if !ok { panic(errors.NewUnreachableError()) } diff --git a/interpreter/value.go b/interpreter/value.go index fe3828d5f0..54756dff7f 100644 --- a/interpreter/value.go +++ b/interpreter/value.go @@ -247,10 +247,15 @@ type OwnedValue interface { GetOwner() common.Address } +type ValueIteratorContext interface { + common.MemoryGauge + NumberValueArithmeticContext +} + // ValueIterator is an iterator which returns values. // When Next returns nil, it signals the end of the iterator. type ValueIterator interface { - Next(interpreter *Interpreter, locationRange LocationRange) Value + Next(context ValueIteratorContext, locationRange LocationRange) Value } func safeAdd(a, b int, locationRange LocationRange) int { diff --git a/interpreter/value_array.go b/interpreter/value_array.go index 0e5075e4cc..5e030f36da 100644 --- a/interpreter/value_array.go +++ b/interpreter/value_array.go @@ -57,7 +57,7 @@ func (v *ArrayValue) Iterator(_ *Interpreter, _ LocationRange) ValueIterator { var _ ValueIterator = ArrayValueIterator{} -func (i ArrayValueIterator) Next(interpreter *Interpreter, _ LocationRange) Value { +func (i ArrayValueIterator) Next(context ValueIteratorContext, _ LocationRange) Value { atreeValue, err := i.atreeIterator.Next() if err != nil { panic(errors.NewExternalError(err)) @@ -69,7 +69,7 @@ func (i ArrayValueIterator) Next(interpreter *Interpreter, _ LocationRange) Valu // atree.Array iterator returns low-level atree.Value, // convert to high-level interpreter.Value - return MustConvertStoredValue(interpreter, atreeValue) + return MustConvertStoredValue(context, atreeValue) } func NewArrayValue( diff --git a/interpreter/value_string.go b/interpreter/value_string.go index 68c6040966..c709714fe6 100644 --- a/interpreter/value_string.go +++ b/interpreter/value_string.go @@ -1068,7 +1068,7 @@ type StringValueIterator struct { var _ ValueIterator = StringValueIterator{} -func (i StringValueIterator) Next(_ *Interpreter, _ LocationRange) Value { +func (i StringValueIterator) Next(_ ValueIteratorContext, _ LocationRange) Value { if !i.graphemes.Next() { return nil } From 1c46ead34dcbc25773794420e4cda97f239dbc4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 30 Jan 2025 10:26:28 -0800 Subject: [PATCH 8/8] format --- interpreter/interpreter_test.go | 37 ++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/interpreter/interpreter_test.go b/interpreter/interpreter_test.go index 010e6a98e9..98e250a4b9 100644 --- a/interpreter/interpreter_test.go +++ b/interpreter/interpreter_test.go @@ -36,7 +36,10 @@ func TestInterpreterOptionalBoxing(t *testing.T) { t.Run("Bool to Bool?", func(t *testing.T) { inter := newTestInterpreter(t) - value := inter.BoxOptional(TrueValue, &sema.OptionalType{Type: sema.BoolType}) + value := inter.BoxOptional( + TrueValue, + &sema.OptionalType{Type: sema.BoolType}, + ) assert.Equal(t, NewUnmeteredSomeValueNonCopying(TrueValue), value, @@ -46,7 +49,10 @@ func TestInterpreterOptionalBoxing(t *testing.T) { t.Run("Bool? to Bool?", func(t *testing.T) { inter := newTestInterpreter(t) - value := inter.BoxOptional(NewUnmeteredSomeValueNonCopying(TrueValue), &sema.OptionalType{Type: sema.BoolType}) + value := inter.BoxOptional( + NewUnmeteredSomeValueNonCopying(TrueValue), + &sema.OptionalType{Type: sema.BoolType}, + ) assert.Equal(t, NewUnmeteredSomeValueNonCopying(TrueValue), value, @@ -56,7 +62,14 @@ func TestInterpreterOptionalBoxing(t *testing.T) { t.Run("Bool? to Bool??", func(t *testing.T) { inter := newTestInterpreter(t) - value := inter.BoxOptional(NewUnmeteredSomeValueNonCopying(TrueValue), &sema.OptionalType{Type: &sema.OptionalType{Type: sema.BoolType}}) + value := inter.BoxOptional( + NewUnmeteredSomeValueNonCopying(TrueValue), + &sema.OptionalType{ + Type: &sema.OptionalType{ + Type: sema.BoolType, + }, + }, + ) assert.Equal(t, NewUnmeteredSomeValueNonCopying( NewUnmeteredSomeValueNonCopying(TrueValue), @@ -69,7 +82,14 @@ func TestInterpreterOptionalBoxing(t *testing.T) { inter := newTestInterpreter(t) // NOTE: - value := inter.BoxOptional(Nil, &sema.OptionalType{Type: &sema.OptionalType{Type: sema.BoolType}}) + value := inter.BoxOptional( + Nil, + &sema.OptionalType{ + Type: &sema.OptionalType{ + Type: sema.BoolType, + }, + }, + ) assert.Equal(t, Nil, value, @@ -80,7 +100,14 @@ func TestInterpreterOptionalBoxing(t *testing.T) { inter := newTestInterpreter(t) // NOTE: - value := inter.BoxOptional(NewUnmeteredSomeValueNonCopying(Nil), &sema.OptionalType{Type: &sema.OptionalType{Type: sema.BoolType}}) + value := inter.BoxOptional( + NewUnmeteredSomeValueNonCopying(Nil), + &sema.OptionalType{ + Type: &sema.OptionalType{ + Type: sema.BoolType, + }, + }, + ) assert.Equal(t, Nil, value,