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, ScreenInput, ScreenPlan, 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 DisplayError(DisplayId),
53 Accept { target: PlaceId, from: AcceptFrom, plan: MovePlan },
54 ArgumentNumber(IntExpr),
57 Environment { display: DisplayId, value: bool },
60 ScreenDisplay { display: DisplayId, screen: ScreenPlan },
63 ScreenAccept { inputs: Vec<ScreenInput>, handled: bool },
67 File(FileOpId),
68 Call(CallId),
69 Cancel(Operand),
70 Sort(SortId),
71 Release(ReleaseId),
72 Return(ReturnId),
73 Report(ReportOp),
74 Invoke(InvokeId),
75 Cics(CicsId),
76 Sql(SqlId),
77 Alter { para: ParaId, to: ParaId },
80 EnterSegment(u8),
84 DebugLine(u32),
86 DebugAlter { range: RangeId, name: SymId, contents: SymId },
89 Markup(MarkupId),
91}
92
93#[derive(Clone, Copy, Debug, PartialEq, Eq)]
95pub enum Step {
96 Next,
97 Arm(u8),
99 GoTo(ParaId),
102 End(Ending),
103 Return(u64),
105 Resume(Resume),
107}
108
109#[derive(Clone, Debug, PartialEq, Eq)]
110pub enum Terminator {
111 Jump(BlockId),
112 Branch { cond: CondId, then: BlockId, otherwise: BlockId },
113 Select(Vec<BlockId>),
115 ParagraphEnd { next: ParaId },
118 GoTo(ParaId),
119 Switch { value: IntExpr, targets: Vec<ParaId>, otherwise: BlockId },
121 PerformEnter { range: RangeId, ret: BlockId, resume: Option<Resume> },
124 ExitProgram { next: BlockId },
126 End(Ending),
127 Abend(AbendId),
128 AlteredGoTo { para: ParaId, otherwise: BlockId },
131 Debug { range: RangeId, name: SymId, next: BlockId },
134}
135
136#[derive(Clone, Copy, Debug, PartialEq, Eq)]
140pub struct Resume {
141 pub para: ParaId,
142 pub block: BlockId,
143}
144
145#[derive(Clone, Copy, Debug, PartialEq, Eq)]
146pub struct Range {
147 pub first: ParaId,
148 pub last: ParaId,
149 pub kind: RangeKind,
150}
151
152impl Range {
153 pub fn region(&self, paragraphs: u32) -> (ParaId, ParaId) {
157 let end = paragraphs.saturating_sub(1);
158 match self.kind {
159 RangeKind::SortProcedure => (0, end),
160 _ if self.last < self.first => (self.first, end),
161 _ => (self.first, self.last),
162 }
163 }
164}
165
166#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
167pub enum RangeKind {
168 Perform,
169 SortProcedure,
170 UseBeforeReporting,
171 UseProcedure,
173 Debugging,
175 Processing,
177}
178
179#[derive(Clone, Debug, Default, PartialEq, Eq)]
181pub struct Declaratives {
182 pub modes: [Option<RangeId>; 4],
185 pub debug_item: Option<(u32, u32)>,
187}
188
189#[derive(Clone, Copy, Debug, PartialEq, Eq)]
192pub struct ReturnPoint {
193 pub frame: u64,
194 pub resume: Option<Resume>,
195}
196
197#[derive(Clone, Debug, PartialEq, Eq)]
202pub struct Frame {
203 pub id: u64,
204 pub kind: FrameKind,
205 pub displaced: Option<ReturnPoint>,
206 pub segment: u8,
207 pub depth: u32,
208 pub temps: Vec<i64>,
209}
210
211#[derive(Clone, Copy, Debug, PartialEq, Eq)]
212pub enum FrameKind {
213 Main,
215 Perform { range: RangeId, ret: BlockId, resume: Option<Resume> },
216 Procedure { range: RangeId },
219}
220
221#[derive(Clone, Debug, Default, PartialEq, Eq)]
224pub struct Returns {
225 pub armed: Vec<Option<ReturnPoint>>,
226 pub saved: BTreeMap<BlockId, Option<ReturnPoint>>,
227 pub frames: Vec<Frame>,
228 pub next_frame: u64,
229}
230
231codec_enum!(Op {
232 Move { from, to, plan, check } = 0,
233 Initialize { target, plan } = 1,
234 Arith(id) = 2,
235 SetAddress { records, address } = 3,
236 SetUpDown { by, down, targets } = 4,
237 Step { var, by, plan, prepass } = 5,
238 SetInt { target, value } = 6,
239 Inspect(id) = 7,
240 String(id) = 8,
241 Unstring(id) = 9,
242 SearchAll(id) = 10,
243 Nest = 11,
244 Unnest(n) = 12,
245 SetTemp(temp, value) = 13,
246 DecTemp(temp) = 14,
247 Display(id) = 15,
248 Accept { target, from, plan } = 16,
249 File(id) = 17,
250 Call(id) = 18,
251 Cancel(name) = 19,
252 Sort(id) = 20,
253 Release(id) = 21,
254 Return(id) = 22,
255 Report(op) = 23,
256 Invoke(id) = 24,
257 Cics(id) = 25,
258 Sql(id) = 26,
259 Alter { para, to } = 27,
260 EnterSegment(priority) = 28,
261 DebugLine(line) = 30,
262 DebugAlter { range, name, contents } = 31,
263 Markup(id) = 32,
264 Set { from, to, plan } = 33,
265 SetCount(temp, odo) = 34,
266 SetEntry { entry, targets } = 35,
267 ArgumentNumber(value) = 36,
268 ScreenDisplay { display, screen } = 37,
269 ScreenAccept { inputs, handled } = 38,
270 Environment { display, value } = 39,
271 DisplayError(id) = 40,
272});
273codec_enum!(Step { Next = 0, Arm(arm) = 1, GoTo(para) = 2, End(ending) = 3, Return(frame) = 4, Resume(resume) = 5 });
274codec_enum!(Terminator {
275 Jump(block) = 0,
276 Branch { cond, then, otherwise } = 1,
277 Select(arms) = 2,
278 ParagraphEnd { next } = 3,
279 GoTo(para) = 4,
280 Switch { value, targets, otherwise } = 5,
281 ExitProgram { next } = 7,
282 End(ending) = 8,
283 Abend(abend) = 9,
284 AlteredGoTo { para, otherwise } = 10,
285 Debug { range, name, next } = 11,
286 PerformEnter { range, ret, resume } = 12,
287});
288codec_struct!(Resume { para, block });
289codec_struct!(Range { first, last, kind });
290codec_enum!(RangeKind { Perform = 0, SortProcedure = 1, UseBeforeReporting = 2, UseProcedure = 3, Debugging = 4, Processing = 5 });
291codec_struct!(Declaratives { modes, debug_item });
292codec_struct!(ReturnPoint { frame, resume });
293codec_struct!(Frame { id, kind, displaced, segment, depth, temps });
294codec_enum!(FrameKind { Main = 0, Perform { range, ret, resume } = 1, Procedure { range } = 2 });
295codec_struct!(Returns { armed, saved, frames, next_frame });