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 ArgumentNumber(IntExpr),
54 File(FileOpId),
55 Call(CallId),
56 Cancel(Operand),
57 Sort(SortId),
58 Release(ReleaseId),
59 Return(ReturnId),
60 Report(ReportOp),
61 Invoke(InvokeId),
62 Cics(CicsId),
63 Sql(SqlId),
64 Alter { para: ParaId, to: ParaId },
67 EnterSegment(u8),
71 DebugLine(u32),
73 DebugAlter { range: RangeId, name: SymId, contents: SymId },
76 Markup(MarkupId),
78}
79
80#[derive(Clone, Copy, Debug, PartialEq, Eq)]
82pub enum Step {
83 Next,
84 Arm(u8),
86 GoTo(ParaId),
89 End(Ending),
90 Return(u64),
92 Resume(Resume),
94}
95
96#[derive(Clone, Debug, PartialEq, Eq)]
97pub enum Terminator {
98 Jump(BlockId),
99 Branch { cond: CondId, then: BlockId, otherwise: BlockId },
100 Select(Vec<BlockId>),
102 ParagraphEnd { next: ParaId },
105 GoTo(ParaId),
106 Switch { value: IntExpr, targets: Vec<ParaId>, otherwise: BlockId },
108 PerformEnter { range: RangeId, ret: BlockId, resume: Option<Resume> },
111 ExitProgram { next: BlockId },
113 End(Ending),
114 Abend(AbendId),
115 AlteredGoTo { para: ParaId, otherwise: BlockId },
118 Debug { range: RangeId, name: SymId, next: BlockId },
121}
122
123#[derive(Clone, Copy, Debug, PartialEq, Eq)]
127pub struct Resume {
128 pub para: ParaId,
129 pub block: BlockId,
130}
131
132#[derive(Clone, Copy, Debug, PartialEq, Eq)]
133pub struct Range {
134 pub first: ParaId,
135 pub last: ParaId,
136 pub kind: RangeKind,
137}
138
139impl Range {
140 pub fn region(&self, paragraphs: u32) -> (ParaId, ParaId) {
144 let end = paragraphs.saturating_sub(1);
145 match self.kind {
146 RangeKind::SortProcedure => (0, end),
147 _ if self.last < self.first => (self.first, end),
148 _ => (self.first, self.last),
149 }
150 }
151}
152
153#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
154pub enum RangeKind {
155 Perform,
156 SortProcedure,
157 UseBeforeReporting,
158 UseProcedure,
160 Debugging,
162 Processing,
164}
165
166#[derive(Clone, Debug, Default, PartialEq, Eq)]
168pub struct Declaratives {
169 pub modes: [Option<RangeId>; 4],
172 pub debug_item: Option<(u32, u32)>,
174}
175
176#[derive(Clone, Copy, Debug, PartialEq, Eq)]
179pub struct ReturnPoint {
180 pub frame: u64,
181 pub resume: Option<Resume>,
182}
183
184#[derive(Clone, Debug, PartialEq, Eq)]
189pub struct Frame {
190 pub id: u64,
191 pub kind: FrameKind,
192 pub displaced: Option<ReturnPoint>,
193 pub segment: u8,
194 pub depth: u32,
195 pub temps: Vec<i64>,
196}
197
198#[derive(Clone, Copy, Debug, PartialEq, Eq)]
199pub enum FrameKind {
200 Main,
202 Perform { range: RangeId, ret: BlockId, resume: Option<Resume> },
203 Procedure { range: RangeId },
206}
207
208#[derive(Clone, Debug, Default, PartialEq, Eq)]
211pub struct Returns {
212 pub armed: Vec<Option<ReturnPoint>>,
213 pub saved: BTreeMap<BlockId, Option<ReturnPoint>>,
214 pub frames: Vec<Frame>,
215 pub next_frame: u64,
216}
217
218codec_enum!(Op {
219 Move { from, to, plan, check } = 0,
220 Initialize { target, plan } = 1,
221 Arith(id) = 2,
222 SetAddress { records, address } = 3,
223 SetUpDown { by, down, targets } = 4,
224 Step { var, by, plan, prepass } = 5,
225 SetInt { target, value } = 6,
226 Inspect(id) = 7,
227 String(id) = 8,
228 Unstring(id) = 9,
229 SearchAll(id) = 10,
230 Nest = 11,
231 Unnest(n) = 12,
232 SetTemp(temp, value) = 13,
233 DecTemp(temp) = 14,
234 Display(id) = 15,
235 Accept { target, from, plan } = 16,
236 File(id) = 17,
237 Call(id) = 18,
238 Cancel(name) = 19,
239 Sort(id) = 20,
240 Release(id) = 21,
241 Return(id) = 22,
242 Report(op) = 23,
243 Invoke(id) = 24,
244 Cics(id) = 25,
245 Sql(id) = 26,
246 Alter { para, to } = 27,
247 EnterSegment(priority) = 28,
248 DebugLine(line) = 30,
249 DebugAlter { range, name, contents } = 31,
250 Markup(id) = 32,
251 Set { from, to, plan } = 33,
252 SetCount(temp, odo) = 34,
253 SetEntry { entry, targets } = 35,
254 ArgumentNumber(value) = 36,
255});
256codec_enum!(Step { Next = 0, Arm(arm) = 1, GoTo(para) = 2, End(ending) = 3, Return(frame) = 4, Resume(resume) = 5 });
257codec_enum!(Terminator {
258 Jump(block) = 0,
259 Branch { cond, then, otherwise } = 1,
260 Select(arms) = 2,
261 ParagraphEnd { next } = 3,
262 GoTo(para) = 4,
263 Switch { value, targets, otherwise } = 5,
264 ExitProgram { next } = 7,
265 End(ending) = 8,
266 Abend(abend) = 9,
267 AlteredGoTo { para, otherwise } = 10,
268 Debug { range, name, next } = 11,
269 PerformEnter { range, ret, resume } = 12,
270});
271codec_struct!(Resume { para, block });
272codec_struct!(Range { first, last, kind });
273codec_enum!(RangeKind { Perform = 0, SortProcedure = 1, UseBeforeReporting = 2, UseProcedure = 3, Debugging = 4, Processing = 5 });
274codec_struct!(Declaratives { modes, debug_item });
275codec_struct!(ReturnPoint { frame, resume });
276codec_struct!(Frame { id, kind, displaced, segment, depth, temps });
277codec_enum!(FrameKind { Main = 0, Perform { range, ret, resume } = 1, Procedure { range } = 2 });
278codec_struct!(Returns { armed, saved, frames, next_frame });