@@ -674,40 +674,29 @@ func (e *interpreterEnvironment) resolveImport(
674
674
importRange ast.Range ,
675
675
) (sema.Import , error ) {
676
676
677
- var elaboration * sema.Elaboration
678
- switch importedLocation {
679
- case stdlib .CryptoCheckerLocation :
680
- cryptoChecker := stdlib .CryptoChecker ()
681
- elaboration = cryptoChecker .Elaboration
682
-
683
- default :
684
-
685
- // Check for cyclic imports
686
- if e .checkedImports [importedLocation ] {
687
- return nil , & sema.CyclicImportsError {
688
- Location : importedLocation ,
689
- Range : importRange ,
690
- }
691
- } else {
692
- e .checkedImports [importedLocation ] = true
693
- defer delete (e .checkedImports , importedLocation )
694
- }
695
-
696
- const getAndSetProgram = true
697
- program , err := e .GetProgram (
698
- importedLocation ,
699
- getAndSetProgram ,
700
- e .checkedImports ,
701
- )
702
- if err != nil {
703
- return nil , err
677
+ // Check for cyclic imports
678
+ if e .checkedImports [importedLocation ] {
679
+ return nil , & sema.CyclicImportsError {
680
+ Location : importedLocation ,
681
+ Range : importRange ,
704
682
}
683
+ } else {
684
+ e .checkedImports [importedLocation ] = true
685
+ defer delete (e .checkedImports , importedLocation )
686
+ }
705
687
706
- elaboration = program .Elaboration
688
+ const getAndSetProgram = true
689
+ program , err := e .GetProgram (
690
+ importedLocation ,
691
+ getAndSetProgram ,
692
+ e .checkedImports ,
693
+ )
694
+ if err != nil {
695
+ return nil , err
707
696
}
708
697
709
698
return sema.ElaborationImport {
710
- Elaboration : elaboration ,
699
+ Elaboration : program . Elaboration ,
711
700
}, nil
712
701
}
713
702
@@ -1006,36 +995,30 @@ func (e *interpreterEnvironment) newInjectedCompositeFieldsHandler() interpreter
1006
995
compositeKind common.CompositeKind ,
1007
996
) map [string ]interpreter.Value {
1008
997
1009
- switch location {
1010
- case stdlib . CryptoCheckerLocation :
1011
- return nil
998
+ switch compositeKind {
999
+ case common . CompositeKindContract :
1000
+ var address Address
1012
1001
1013
- default :
1014
- switch compositeKind {
1015
- case common .CompositeKindContract :
1016
- var address Address
1017
-
1018
- switch location := location .(type ) {
1019
- case common.AddressLocation :
1020
- address = location .Address
1021
- default :
1022
- return nil
1023
- }
1002
+ switch location := location .(type ) {
1003
+ case common.AddressLocation :
1004
+ address = location .Address
1005
+ default :
1006
+ return nil
1007
+ }
1024
1008
1025
- addressValue := interpreter .NewAddressValue (
1026
- inter ,
1027
- address ,
1028
- )
1009
+ addressValue := interpreter .NewAddressValue (
1010
+ inter ,
1011
+ address ,
1012
+ )
1029
1013
1030
- return map [string ]interpreter.Value {
1031
- sema .ContractAccountFieldName : stdlib .NewAccountReferenceValue (
1032
- inter ,
1033
- e ,
1034
- addressValue ,
1035
- interpreter .FullyEntitledAccountAccess ,
1036
- interpreter .EmptyLocationRange ,
1037
- ),
1038
- }
1014
+ return map [string ]interpreter.Value {
1015
+ sema .ContractAccountFieldName : stdlib .NewAccountReferenceValue (
1016
+ inter ,
1017
+ e ,
1018
+ addressValue ,
1019
+ interpreter .FullyEntitledAccountAccess ,
1020
+ interpreter .EmptyLocationRange ,
1021
+ ),
1039
1022
}
1040
1023
}
1041
1024
@@ -1046,36 +1029,22 @@ func (e *interpreterEnvironment) newInjectedCompositeFieldsHandler() interpreter
1046
1029
func (e * interpreterEnvironment ) newImportLocationHandler () interpreter.ImportLocationHandlerFunc {
1047
1030
return func (inter * interpreter.Interpreter , location common.Location ) interpreter.Import {
1048
1031
1049
- switch location {
1050
- case stdlib .CryptoCheckerLocation :
1051
- cryptoChecker := stdlib .CryptoChecker ()
1052
- program := interpreter .ProgramFromChecker (cryptoChecker )
1053
- subInterpreter , err := inter .NewSubInterpreter (program , location )
1054
- if err != nil {
1055
- panic (err )
1056
- }
1057
- return interpreter.InterpreterImport {
1058
- Interpreter : subInterpreter ,
1059
- }
1060
-
1061
- default :
1062
- const getAndSetProgram = true
1063
- program , err := e .GetProgram (
1064
- location ,
1065
- getAndSetProgram ,
1066
- importResolutionResults {},
1067
- )
1068
- if err != nil {
1069
- panic (err )
1070
- }
1032
+ const getAndSetProgram = true
1033
+ program , err := e .GetProgram (
1034
+ location ,
1035
+ getAndSetProgram ,
1036
+ importResolutionResults {},
1037
+ )
1038
+ if err != nil {
1039
+ panic (err )
1040
+ }
1071
1041
1072
- subInterpreter , err := inter .NewSubInterpreter (program , location )
1073
- if err != nil {
1074
- panic (err )
1075
- }
1076
- return interpreter.InterpreterImport {
1077
- Interpreter : subInterpreter ,
1078
- }
1042
+ subInterpreter , err := inter .NewSubInterpreter (program , location )
1043
+ if err != nil {
1044
+ panic (err )
1045
+ }
1046
+ return interpreter.InterpreterImport {
1047
+ Interpreter : subInterpreter ,
1079
1048
}
1080
1049
}
1081
1050
}
@@ -1123,45 +1092,32 @@ func (e *interpreterEnvironment) newCompositeValueFunctionsHandler() interpreter
1123
1092
func (e * interpreterEnvironment ) loadContract (
1124
1093
inter * interpreter.Interpreter ,
1125
1094
compositeType * sema.CompositeType ,
1126
- constructorGenerator func (common.Address ) * interpreter.HostFunctionValue ,
1127
- invocationRange ast.Range ,
1095
+ _ func (common.Address ) * interpreter.HostFunctionValue ,
1096
+ _ ast.Range ,
1128
1097
) * interpreter.CompositeValue {
1129
1098
1130
- switch compositeType .Location {
1131
- case stdlib .CryptoCheckerLocation :
1132
- contract , err := stdlib .NewCryptoContract (
1133
- inter ,
1134
- constructorGenerator (common .ZeroAddress ),
1135
- invocationRange ,
1136
- )
1137
- if err != nil {
1138
- panic (err )
1139
- }
1140
- return contract
1141
-
1142
- default :
1143
-
1144
- var storedValue interpreter.Value
1145
-
1146
- switch location := compositeType .Location .(type ) {
1099
+ var contractValue interpreter.Value
1147
1100
1148
- case common.AddressLocation :
1149
- storageMap := e .storage .GetStorageMap (
1150
- location .Address ,
1151
- StorageDomainContract ,
1152
- false ,
1101
+ location := compositeType .Location
1102
+ if addressLocation , ok := location .(common.AddressLocation ); ok {
1103
+ storageMap := e .storage .GetStorageMap (
1104
+ addressLocation .Address ,
1105
+ StorageDomainContract ,
1106
+ false ,
1107
+ )
1108
+ if storageMap != nil {
1109
+ contractValue = storageMap .ReadValue (
1110
+ inter ,
1111
+ interpreter .StringStorageMapKey (addressLocation .Name ),
1153
1112
)
1154
- if storageMap != nil {
1155
- storedValue = storageMap .ReadValue (inter , interpreter .StringStorageMapKey (location .Name ))
1156
- }
1157
- }
1158
-
1159
- if storedValue == nil {
1160
- panic (errors .NewDefaultUserError ("failed to load contract: %s" , compositeType .Location ))
1161
1113
}
1114
+ }
1162
1115
1163
- return storedValue .(* interpreter.CompositeValue )
1116
+ if contractValue == nil {
1117
+ panic (errors .NewDefaultUserError ("failed to load contract: %s" , location ))
1164
1118
}
1119
+
1120
+ return contractValue .(* interpreter.CompositeValue )
1165
1121
}
1166
1122
1167
1123
func (e * interpreterEnvironment ) newOnFunctionInvocationHandler () func (_ * interpreter.Interpreter ) {
0 commit comments