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