-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtins.go
79 lines (61 loc) · 2.28 KB
/
builtins.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
77
78
79
package compiler
type builtin struct {
name string
opcodes string
args []typeDesc
result typeDesc
}
var builtins = []builtin{
{"sha3", "SHA3", []typeDesc{nilType}, hashType},
{"sha256", "SHA256", []typeDesc{nilType}, hashType},
{"size", "SIZE SWAP DROP", []typeDesc{nilType}, intType},
{"abs", "ABS", []typeDesc{intType}, intType},
{"min", "MIN", []typeDesc{intType, intType}, intType},
{"max", "MAX", []typeDesc{intType, intType}, intType},
{"checkTxSig", "TXSIGHASH SWAP CHECKSIG", []typeDesc{pubkeyType, sigType}, boolType},
{"concat", "CAT", []typeDesc{nilType, nilType}, strType},
{"concatpush", "CATPUSHDATA", []typeDesc{nilType, nilType}, strType},
{"below", "BLOCKHEIGHT GREATERTHAN", []typeDesc{intType}, boolType},
{"above", "BLOCKHEIGHT LESSTHAN", []typeDesc{intType}, boolType},
{"checkTxMultiSig", "", []typeDesc{listType, listType}, boolType}, // WARNING WARNING WOOP WOOP special case
}
type binaryOp struct {
op string
precedence int
opcodes string
left, right, result typeDesc
}
var binaryOps = []binaryOp{
// disjunctions disallowed (for now?)
// {"||", 1, "BOOLOR", "Boolean", "Boolean", "Boolean"},
// and disallow this too
// {"&&", 2, "BOOLAND", "Boolean", "Boolean", "Boolean"},
{">", 3, "GREATERTHAN", "Integer", "Integer", "Boolean"},
{"<", 3, "LESSTHAN", "Integer", "Integer", "Boolean"},
{">=", 3, "GREATERTHANOREQUAL", "Integer", "Integer", "Boolean"},
{"<=", 3, "LESSTHANOREQUAL", "Integer", "Integer", "Boolean"},
{"==", 3, "EQUAL", "", "", "Boolean"},
{"!=", 3, "EQUAL NOT", "", "", "Boolean"},
{"^", 4, "XOR", "", "", ""},
{"|", 4, "OR", "", "", ""},
{"+", 4, "ADD", "Integer", "Integer", "Integer"},
{"-", 4, "SUB", "Integer", "Integer", "Integer"},
// {"&^", 5, "INVERT AND", "", "", ""},
{"&", 5, "AND", "", "", ""},
{"<<", 5, "LSHIFT", "Integer", "Integer", "Integer"},
{">>", 5, "RSHIFT", "Integer", "Integer", "Integer"},
{"%", 5, "MOD", "Integer", "Integer", "Integer"},
{"*", 5, "MUL", "Integer", "Integer", "Integer"},
{"/", 5, "DIV", "Integer", "Integer", "Integer"},
}
type unaryOp struct {
op string
opcodes string
operand, result typeDesc
}
var unaryOps = []unaryOp{
{"-", "NEGATE", "Integer", "Integer"},
// not not allowed (for now?)
// {"!", "NOT", "Boolean", "Boolean"},
{"~", "INVERT", "", ""},
}