summaryrefslogtreecommitdiff
path: root/vendor/github.com/dalzilio/rudd/operator.go
blob: 55a5627953d46409441298a03555b6708354f965 (plain)
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
// Copyright (c) 2021 Silvano DAL ZILIO
//
// MIT License

package rudd

// Operator describe the potential (binary) operations available on an Apply.
// Only the first four operators (from OPand to OPnand) can be used in AppEx.
type Operator int

const (
	OPand Operator = iota
	OPxor
	OPor
	OPnand
	OPnor
	OPimp
	OPbiimp
	OPdiff
	OPless
	OPinvimp
	// opnot, for negation, is the only unary operation. It should not be used
	// in Apply
	opnot
)

var opnames = [12]string{
	OPand:    "and",
	OPxor:    "xor",
	OPor:     "or",
	OPnand:   "nand",
	OPnor:    "nor",
	OPimp:    "imp",
	OPbiimp:  "biimp",
	OPdiff:   "diff",
	OPless:   "less",
	OPinvimp: "invimp",
	opnot:    "not",
}

func (op Operator) String() string {
	return opnames[op]
}

var opres = [12][2][2]int{
	//                      00    01               10    11
	OPand:    {0: [2]int{0: 0, 1: 0}, 1: [2]int{0: 0, 1: 1}}, // 0001
	OPxor:    {0: [2]int{0: 0, 1: 1}, 1: [2]int{0: 1, 1: 0}}, // 0110
	OPor:     {0: [2]int{0: 0, 1: 1}, 1: [2]int{0: 1, 1: 1}}, // 0111
	OPnand:   {0: [2]int{0: 1, 1: 1}, 1: [2]int{0: 1, 1: 0}}, // 1110
	OPnor:    {0: [2]int{0: 1, 1: 0}, 1: [2]int{0: 0, 1: 0}}, // 1000
	OPimp:    {0: [2]int{0: 1, 1: 1}, 1: [2]int{0: 0, 1: 1}}, // 1101
	OPbiimp:  {0: [2]int{0: 1, 1: 0}, 1: [2]int{0: 0, 1: 1}}, // 1001
	OPdiff:   {0: [2]int{0: 0, 1: 0}, 1: [2]int{0: 1, 1: 0}}, // 0010
	OPless:   {0: [2]int{0: 0, 1: 1}, 1: [2]int{0: 0, 1: 0}}, // 0100
	OPinvimp: {0: [2]int{0: 1, 1: 0}, 1: [2]int{0: 1, 1: 1}}, // 1011
}