-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclassicals.js
73 lines (70 loc) · 2.21 KB
/
classicals.js
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
// initializations and operations on classical registers
const utils = require('./utils.js');
var inits = {
TRUE: (classical_index) => {
classical_index = utils.validInt(classical_index);
return {
classical_index: classical_index,
maxClassicalBit: classical_index,
code: 'TRUE ro[' + classical_index + ']'
};
},
FALSE: (classical_index) => {
classical_index = utils.validInt(classical_index);
return {
classical_index: classical_index,
maxClassicalBit: classical_index,
code: 'FALSE ro[' + classical_index + ']'
};
},
};
var operations = {
NOT: (classical_index) => {
classical_index = utils.validInt(classical_index);
return {
classical_index: classical_index,
maxClassicalBit: classical_index,
code: 'NOT ro[' + classical_index + ']'
};
},
AND: (classical_a, classical_b) => {
classical_a = utils.validInt(classical_a);
classical_b = utils.validInt(classical_b);
return {
classical_indexes: [classical_a, classical_b],
maxClassicalBit: Math.max(classical_a, classical_b),
code: 'AND ro[' + classical_a + '] ro[' + classical_b + ']'
};
},
OR: (classical_a, classical_b) => {
classical_a = utils.validInt(classical_a);
classical_b = utils.validInt(classical_b);
return {
classical_indexes: [classical_a, classical_b],
maxClassicalBit: Math.max(classical_a, classical_b),
code: 'OR ro[' + classical_a + '] ro[' + classical_b + ']'
};
},
MOVE: (classical_a, classical_b) => {
classical_a = utils.validInt(classical_a);
classical_b = utils.validInt(classical_b);
return {
classical_indexes: [classical_a, classical_b],
maxClassicalBit: Math.max(classical_a, classical_b),
code: 'MOVE ro[' + classical_a + '] ro[' + classical_b + ']'
};
},
EXCHANGE: (classical_a, classical_b) => {
classical_a = utils.validInt(classical_a);
classical_b = utils.validInt(classical_b);
return {
classical_indexes: [classical_a, classical_b],
maxClassicalBit: Math.max(classical_a, classical_b),
code: 'EXCHANGE ro[' + classical_a + '] ro[' + classical_b + ']'
};
}
};
module.exports = {
inits: inits,
operations: operations
};