never executed always true always false
1 module HelVM.HelMA.Automaton.Instruction.Extras.Constructors where
2
3 import HelVM.HelMA.Automaton.Instruction.Extras.Common
4
5 import HelVM.HelMA.Automaton.Instruction.Groups.CFInstruction
6 import HelVM.HelMA.Automaton.Instruction.Groups.IOInstruction
7 import HelVM.HelMA.Automaton.Instruction.Groups.LSInstruction
8 import HelVM.HelMA.Automaton.Instruction.Groups.SMInstruction
9
10 import HelVM.HelMA.Automaton.Instruction
11
12 -- | Constructors
13
14 -- | ISM
15
16 immediateBinaryI ∷ Integer → BinaryOperation → Instruction
17 immediateBinaryI i = ISM . SPure . Unary . UImmediate i
18
19 consI ∷ Integer → Instruction
20 consI = sal . Cons
21
22 addI , subI , mulI , divI , modI ∷ Instruction
23 addI = binary Add
24 subI = binary Sub
25 mulI = binary Mul
26 divI = binary Div
27 modI = binary Mod
28
29 divModI , negI , halibutI ∷ Instruction
30 divModI = binaries [Mod, Div]
31 negI = unary Neg
32 halibutI = sal Halibut
33
34 dupI , swapI , rotI , copyTI , discardI ∷ Instruction
35 dupI = copyII 0
36 swapI = moveII 1
37 rotI = moveII 2
38 copyTI = sal $ Indexed ITop Copy
39 discardI = sal Discard
40
41 copyII ∷ ImmediateIndex → Instruction
42 copyII = manipulationII Copy
43
44 moveII ∷ ImmediateIndex → Instruction
45 moveII = manipulationII Move
46
47 slideII ∷ ImmediateIndex → Instruction
48 slideII = manipulationII Slide
49
50 manipulationII ∷ IndexedOperation → ImmediateIndex → Instruction
51 manipulationII op i = sal $ Indexed (IImmediate i) op
52
53 sInputI , sOutputI , sOutputDecI ∷ Instruction
54 sInputI = sio InputChar
55 sOutputI = sio OutputChar
56 sOutputDecI = sio OutputDec
57
58 binaries ∷ [BinaryOperation] → Instruction
59 binaries = sal . Binaries
60
61 binary ∷ BinaryOperation → Instruction
62 binary = sal . Binary
63
64 unary ∷ UnaryOperation → Instruction
65 unary = sal . Unary
66
67 sal ∷ SPureInstruction → Instruction
68 sal = ISM . SPure
69
70 sio ∷ IOInstruction → Instruction
71 sio = ISM . SIO
72
73 -- | ICF
74
75 markNI ∷ Natural → Instruction
76 markNI = ICF . Mark . MNatural
77
78 markSI ∷ Label → Instruction
79 markSI = ICF . Mark . MArtificial
80
81 jumpTI ∷ Instruction
82 jumpTI = labeledT Jump
83
84 jumpII ∷ Natural → Instruction
85 jumpII = labeledI Jump
86
87 callSI , jumpSI ∷ Label → Instruction
88 callSI = labeledA Call
89 jumpSI = labeledA Jump
90
91 branchSwapI ∷ BranchTest → Instruction
92 branchSwapI = ICF . Branch BSwapped
93
94 bNeTI ∷ Instruction
95 bNeTI = branchT NE
96
97 bNeII ∷ Natural → Instruction
98 bNeII = branchI NE
99
100 bEzSI , bLtzSI ∷ Label → Instruction
101 bEzSI = branchA EZ
102 bLtzSI = branchA LTZ
103
104 branchT ∷ BranchTest → Instruction
105 branchT = ICF . Branch BTop
106
107 branchI ∷ BranchTest → Natural → Instruction
108 branchI op n = ICF $ Branch (BImmediate n) op
109
110 branchA ∷ BranchTest → Label → Instruction
111 branchA op l = ICF $ Branch (BArtificial l) op
112
113 labeledT ∷ LabelOperation → Instruction
114 labeledT = ICF . Labeled LTop
115
116 labeledI ∷ LabelOperation → Natural → Instruction
117 labeledI op n = ICF $ Labeled (LImmediate n) op
118
119 labeledA ∷ LabelOperation → Label → Instruction
120 labeledA op l = ICF $ Labeled (LArtificial l) op
121
122 returnI ∷ Instruction
123 returnI = ICF Return
124
125 -- | ILS
126
127 storeI , loadI ∷ Instruction
128 storeI = ILS Store
129 loadI = ILS Load
130
131 mInputI , mInputDecI ∷ Instruction
132 mInputI = mio InputChar
133 mInputDecI = mio InputDec
134
135 mio ∷ IOInstruction → Instruction
136 mio = ILS . MIO
137
138 storeIDI ∷ Integer → ImmediateIndex → Instruction
139 storeIDI v = ILS . StoreID v
140
141 loadDI ∷ ImmediateIndex → Instruction
142 loadDI = ILS . LoadD
143
144 moveDI ∷ ImmediateIndex → ImmediateIndex → Instruction
145 moveDI a = ILS . MoveD a