OSDN Git Service

optimise equity commandline (#36)
[bytom/equity.git] / compiler / builtins.go
1 package compiler
2
3 type builtin struct {
4         name    string
5         opcodes string
6         args    []typeDesc
7         result  typeDesc
8 }
9
10 var builtins = []builtin{
11         {"sha3", "SHA3", []typeDesc{nilType}, hashType},
12         {"sha256", "SHA256", []typeDesc{nilType}, hashType},
13         {"size", "SIZE SWAP DROP", []typeDesc{nilType}, intType},
14         {"abs", "ABS", []typeDesc{intType}, intType},
15         {"min", "MIN", []typeDesc{intType, intType}, intType},
16         {"max", "MAX", []typeDesc{intType, intType}, intType},
17         {"checkTxSig", "TXSIGHASH SWAP CHECKSIG", []typeDesc{pubkeyType, sigType}, boolType},
18         {"checkMsgSig", "CHECKSIG", []typeDesc{pubkeyType, hashType, signType}, boolType},
19         {"concat", "CAT", []typeDesc{nilType, nilType}, strType},
20         {"concatpush", "CATPUSHDATA", []typeDesc{nilType, nilType}, strType},
21         {"below", "BLOCKHEIGHT GREATERTHAN", []typeDesc{intType}, boolType},
22         {"above", "BLOCKHEIGHT LESSTHAN", []typeDesc{intType}, boolType},
23         {"checkTxMultiSig", "", []typeDesc{listType, listType}, boolType}, // WARNING WARNING WOOP WOOP special case
24 }
25
26 type binaryOp struct {
27         op         string
28         precedence int
29         opcodes    string
30
31         left, right, result typeDesc
32 }
33
34 var binaryOps = []binaryOp{
35         {"||", 1, "BOOLOR", "Boolean", "Boolean", "Boolean"},
36         {"&&", 2, "BOOLAND", "Boolean", "Boolean", "Boolean"},
37
38         {">", 3, "GREATERTHAN", "Integer", "Integer", "Boolean"},
39         {"<", 3, "LESSTHAN", "Integer", "Integer", "Boolean"},
40         {">=", 3, "GREATERTHANOREQUAL", "Integer", "Integer", "Boolean"},
41         {"<=", 3, "LESSTHANOREQUAL", "Integer", "Integer", "Boolean"},
42
43         {"==", 3, "EQUAL", "", "", "Boolean"},
44         {"!=", 3, "EQUAL NOT", "", "", "Boolean"},
45
46         {"^", 4, "XOR", "", "", ""},
47         {"|", 4, "OR", "", "", ""},
48
49         {"+", 4, "ADD", "Integer", "Integer", "Integer"},
50         {"-", 4, "SUB", "Integer", "Integer", "Integer"},
51
52         // {"&^", 5, "INVERT AND", "", "", ""},
53         {"&", 5, "AND", "", "", ""},
54
55         {"<<", 5, "LSHIFT", "Integer", "Integer", "Integer"},
56         {">>", 5, "RSHIFT", "Integer", "Integer", "Integer"},
57
58         {"%", 5, "MOD", "Integer", "Integer", "Integer"},
59         {"*", 5, "MUL", "Integer", "Integer", "Integer"},
60         {"/", 5, "DIV", "Integer", "Integer", "Integer"},
61 }
62
63 type unaryOp struct {
64         op      string
65         opcodes string
66
67         operand, result typeDesc
68 }
69
70 var unaryOps = []unaryOp{
71         {"-", "NEGATE", "Integer", "Integer"},
72
73         {"!", "NOT", "Boolean", "Boolean"},
74
75         {"~", "INVERT", "", ""},
76 }