github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/equity/compiler/types.go (about) 1 package compiler 2 3 type typeDesc string 4 5 var ( 6 amountType = typeDesc("Amount") 7 assetType = typeDesc("Asset") 8 boolType = typeDesc("Boolean") 9 contractType = typeDesc("Contract") 10 hashType = typeDesc("Hash") 11 intType = typeDesc("Integer") 12 listType = typeDesc("List") 13 nilType = typeDesc("") 14 predType = typeDesc("Predicate") 15 progType = typeDesc("Program") 16 pubkeyType = typeDesc("PublicKey") 17 sigType = typeDesc("Signature") 18 strType = typeDesc("String") 19 20 sha3StrType = typeDesc("Sha3(String)") 21 sha3PubkeyType = typeDesc("Sha3(PublicKey)") 22 sha256StrType = typeDesc("Sha256(String)") 23 sha256PubkeyType = typeDesc("Sha256(PublicKey)") 24 ) 25 26 var types = map[string]typeDesc{ 27 string(amountType): amountType, 28 string(assetType): assetType, 29 string(boolType): boolType, 30 string(hashType): hashType, 31 string(intType): intType, 32 string(listType): listType, 33 string(nilType): nilType, 34 string(predType): predType, 35 string(progType): progType, 36 string(pubkeyType): pubkeyType, 37 string(sigType): sigType, 38 string(strType): strType, 39 40 string(sha3StrType): sha3StrType, 41 string(sha3PubkeyType): sha3PubkeyType, 42 string(sha256StrType): sha256StrType, 43 string(sha256PubkeyType): sha256PubkeyType, 44 } 45 46 func isHashSubtype(t typeDesc) bool { 47 switch t { 48 case sha3StrType, sha3PubkeyType, sha256StrType, sha256PubkeyType: 49 return true 50 } 51 return false 52 } 53 54 func propagateType(contract *Contract, clause *Clause, env *environ, t typeDesc, e expression) { 55 v, ok := e.(varRef) 56 if !ok { 57 return 58 } 59 if entry := env.lookup(string(v)); entry != nil { 60 entry.t = t 61 for _, p := range contract.Params { 62 if p.Name == string(v) { 63 p.InferredType = t 64 return 65 } 66 } 67 for _, p := range clause.Params { 68 if p.Name == string(v) { 69 p.InferredType = t 70 return 71 } 72 } 73 } 74 }