1use super::{
5 AbendId, ArithId, BlockId, CallId, CicsId, CondId, DisplayId, ExprId, FileOpId, InitId, InspectId, IntExpr,
6 InvokeId, MarkupId, MovePlan, Odo, Operand, ParaId, PlaceId, RangeId, ReleaseId, ReportOp, ReturnId, SearchAllId, SenderCheck, SortId, SqlId,
7 StepPlan, StringId, SymId, TempId, UnstringId, UpDown,
8};
9use crate::abend::Ending;
10use crate::vocab::AcceptFrom;
11use crate::{codec_enum, codec_struct};
12use std::collections::BTreeMap;
13
14#[derive(Clone, Debug, PartialEq, Eq)]
15pub enum Op {
16 Move { from: Operand, to: PlaceId, plan: MovePlan, check: SenderCheck },
18 Set { from: Operand, to: PlaceId, plan: MovePlan },
21 Initialize { target: PlaceId, plan: InitId },
22 Arith(ArithId),
23 SetAddress { records: Vec<u16>, address: Operand },
26 SetUpDown { by: IntExpr, down: bool, targets: Vec<(PlaceId, UpDown)> },
28 SetEntry { entry: Operand, targets: Vec<PlaceId> },
32 Step { var: PlaceId, by: ExprId, plan: StepPlan, prepass: Vec<PlaceId> },
35 SetInt { target: PlaceId, value: IntExpr },
37 Inspect(InspectId),
38 String(StringId),
39 Unstring(UnstringId),
40 SearchAll(SearchAllId),
41 Nest,
43 Unnest(u8),
44 SetTemp(TempId, IntExpr),
45 DecTemp(TempId),
46 SetCount(TempId, Odo),
49 Display(DisplayId),
50 Accept { target: PlaceId, from: AcceptFrom, plan: MovePlan },
51 File(FileOpId),
52 Call(CallId),
53 Cancel(Operand),
54 Sort(SortId),
55 Release(ReleaseId),
56 Return(ReturnId),
57 Report(ReportOp),
58 Invoke(InvokeId),
59 Cics(CicsId),
60 Sql(SqlId),
61 Alter { para: ParaId, to: ParaId },
64 EnterSegment(u8),
68 DebugLine(u32),
70 DebugAlter { range: RangeId, name: SymId, contents: SymId },
73 Markup(MarkupId),
75}
76
77#[derive(Clone, Copy, Debug, PartialEq, Eq)]
79pub enum Step {
80 Next,
81 Arm(u8),
83 GoTo(ParaId),
86 End(Ending),
87 Return(u64),
89 Resume(Resume),
91}
92
93#[derive(Clone, Debug, PartialEq, Eq)]
94pub enum Terminator {
95 Jump(BlockId),
96 Branch { cond: CondId, then: BlockId, otherwise: BlockId },
97 Select(Vec<BlockId>),
99 ParagraphEnd { next: ParaId },
102 GoTo(ParaId),
103 Switch { value: IntExpr, targets: Vec<ParaId>, otherwise: BlockId },
105 PerformEnter { range: RangeId, ret: BlockId, resume: Option<Resume> },
108 ExitProgram { next: BlockId },
110 End(Ending),
111 Abend(AbendId),
112 AlteredGoTo { para: ParaId, otherwise: BlockId },
115 Debug { range: RangeId, name: SymId, next: BlockId },
118}
119
120#[derive(Clone, Copy, Debug, PartialEq, Eq)]
124pub struct Resume {
125 pub para: ParaId,
126 pub block: BlockId,
127}
128
129#[derive(Clone, Copy, Debug, PartialEq, Eq)]
130pub struct Range {
131 pub first: ParaId,
132 pub last: ParaId,
133 pub kind: RangeKind,
134}
135
136impl Range {
137 pub fn region(&self, paragraphs: u32) -> (ParaId, ParaId) {
141 let end = paragraphs.saturating_sub(1);
142 match self.kind {
143 RangeKind::SortProcedure => (0, end),
144 _ if self.last < self.first => (self.first, end),
145 _ => (self.first, self.last),
146 }
147 }
148}
149
150#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
151pub enum RangeKind {
152 Perform,
153 SortProcedure,
154 UseBeforeReporting,
155 UseProcedure,
157 Debugging,
159 Processing,
161}
162
163#[derive(Clone, Debug, Default, PartialEq, Eq)]
165pub struct Declaratives {
166 pub modes: [Option<RangeId>; 4],
169 pub debug_item: Option<(u32, u32)>,
171}
172
173#[derive(Clone, Copy, Debug, PartialEq, Eq)]
176pub struct ReturnPoint {
177 pub frame: u64,
178 pub resume: Option<Resume>,
179}
180
181#[derive(Clone, Debug, PartialEq, Eq)]
186pub struct Frame {
187 pub id: u64,
188 pub kind: FrameKind,
189 pub displaced: Option<ReturnPoint>,
190 pub segment: u8,
191 pub depth: u32,
192 pub temps: Vec<i64>,
193}
194
195#[derive(Clone, Copy, Debug, PartialEq, Eq)]
196pub enum FrameKind {
197 Main,
199 Perform { range: RangeId, ret: BlockId, resume: Option<Resume> },
200 Procedure { range: RangeId },
203}
204
205#[derive(Clone, Debug, Default, PartialEq, Eq)]
208pub struct Returns {
209 pub armed: Vec<Option<ReturnPoint>>,
210 pub saved: BTreeMap<BlockId, Option<ReturnPoint>>,
211 pub frames: Vec<Frame>,
212 pub next_frame: u64,
213}
214
215codec_enum!(Op {
216 Move { from, to, plan, check } = 0,
217 Initialize { target, plan } = 1,
218 Arith(id) = 2,
219 SetAddress { records, address } = 3,
220 SetUpDown { by, down, targets } = 4,
221 Step { var, by, plan, prepass } = 5,
222 SetInt { target, value } = 6,
223 Inspect(id) = 7,
224 String(id) = 8,
225 Unstring(id) = 9,
226 SearchAll(id) = 10,
227 Nest = 11,
228 Unnest(n) = 12,
229 SetTemp(temp, value) = 13,
230 DecTemp(temp) = 14,
231 Display(id) = 15,
232 Accept { target, from, plan } = 16,
233 File(id) = 17,
234 Call(id) = 18,
235 Cancel(name) = 19,
236 Sort(id) = 20,
237 Release(id) = 21,
238 Return(id) = 22,
239 Report(op) = 23,
240 Invoke(id) = 24,
241 Cics(id) = 25,
242 Sql(id) = 26,
243 Alter { para, to } = 27,
244 EnterSegment(priority) = 28,
245 DebugLine(line) = 30,
246 DebugAlter { range, name, contents } = 31,
247 Markup(id) = 32,
248 Set { from, to, plan } = 33,
249 SetCount(temp, odo) = 34,
250 SetEntry { entry, targets } = 35,
251});
252codec_enum!(Step { Next = 0, Arm(arm) = 1, GoTo(para) = 2, End(ending) = 3, Return(frame) = 4, Resume(resume) = 5 });
253codec_enum!(Terminator {
254 Jump(block) = 0,
255 Branch { cond, then, otherwise } = 1,
256 Select(arms) = 2,
257 ParagraphEnd { next } = 3,
258 GoTo(para) = 4,
259 Switch { value, targets, otherwise } = 5,
260 ExitProgram { next } = 7,
261 End(ending) = 8,
262 Abend(abend) = 9,
263 AlteredGoTo { para, otherwise } = 10,
264 Debug { range, name, next } = 11,
265 PerformEnter { range, ret, resume } = 12,
266});
267codec_struct!(Resume { para, block });
268codec_struct!(Range { first, last, kind });
269codec_enum!(RangeKind { Perform = 0, SortProcedure = 1, UseBeforeReporting = 2, UseProcedure = 3, Debugging = 4, Processing = 5 });
270codec_struct!(Declaratives { modes, debug_item });
271codec_struct!(ReturnPoint { frame, resume });
272codec_struct!(Frame { id, kind, displaced, segment, depth, temps });
273codec_enum!(FrameKind { Main = 0, Perform { range, ret, resume } = 1, Procedure { range } = 2 });
274codec_struct!(Returns { armed, saved, frames, next_frame });