Skip to main content

ironwork_rt/lir/
payload.rs

1//! Statement payloads from lir.md §9: MOVE, INITIALIZE, DISPLAY, SEARCH ALL, FUNCTION and INVOKE,
2//! and a placeholder for each payload whose service is not in `rt` yet. DISPLAY's, SEARCH ALL's and
3//! those of `text`, `call` and `sql` are generic over the handles they name (semantics-library.md §9,
4//! C6): the LIR's ids by default, the walker's own references in the interpreter.
5
6use super::{AbendId, Comparand, Compare, Count, DebugId, ExprId, Operand, PlaceId, RefMod, StorePlan, SymId};
7use crate::vocab::Figurative;
8use crate::{codec_enum, codec_struct};
9use zarch::hfp::Precision;
10
11#[derive(Clone, Copy, Debug, PartialEq, Eq)]
12pub enum MovePlan {
13    Alnum { image: Image, justified: bool },
14    AlnumEdited { image: Image, edit: u32, positions: u32 },
15    National(NationalFrom),
16    Numeric { from: NumericFrom, store: StorePlan },
17    Float { from: FloatFrom, precision: Precision },
18    Address,
19    Index,
20    Refused(AbendId),
21}
22
23#[derive(Clone, Copy, Debug, PartialEq, Eq)]
24pub enum Image {
25    Bytes,
26    All,
27    Figurative,
28    Digits { digits: u32 },
29}
30
31#[derive(Clone, Copy, Debug, PartialEq, Eq)]
32pub enum NationalFrom {
33    Units,
34    Decoded,
35    Figurative,
36}
37
38#[derive(Clone, Copy, Debug, PartialEq, Eq)]
39pub enum NumericFrom {
40    Value,
41    /// NUMPROC(PFD), packed to packed of the same kind and scale: the bytes.
42    PackedCopy,
43    Float,
44    Zero,
45    /// A figurative other than ZERO, or an ALL literal: bytes filled, not converted.
46    Fill,
47    /// Alphanumeric bytes read as an unsigned zoned integer of their length.
48    Zoned,
49    DeEdit { edit: u32, digits: u32, scale: u32 },
50}
51
52#[derive(Clone, Copy, Debug, PartialEq, Eq)]
53pub enum FloatFrom {
54    Float,
55    Fixed,
56    Zero,
57}
58
59/// INITIALIZE of one item: each elementary item the walk reaches, every occurrence listed.
60#[derive(Clone, Debug, PartialEq, Eq)]
61pub struct InitPlan {
62    pub fields: Vec<InitField>,
63}
64
65/// SPACE, ZERO or NULL, as the walker gives the item's kind, moved into `len` bytes at `offset` from
66/// the target's start.
67#[derive(Clone, Copy, Debug, PartialEq, Eq)]
68pub struct InitField {
69    pub offset: u32,
70    pub len: u32,
71    pub value: Figurative,
72    pub store: MovePlan,
73}
74
75/// DISPLAY's items, each shown as the walker shows its kind, then a newline unless NO ADVANCING.
76#[derive(Clone, Debug, PartialEq, Eq)]
77pub struct DisplayPlan<P = PlaceId, O = Operand> {
78    pub items: Vec<DisplayItem<P, O>>,
79    pub no_advancing: bool,
80}
81
82#[derive(Clone, Copy, Debug, PartialEq, Eq)]
83pub enum DisplayItem<P = PlaceId, O = Operand> {
84    /// Groups, alphanumeric, zoned and edited items: the storage in the program's code page.
85    Bytes(P),
86    National(P),
87    /// Packed and binary items: the value's last `digits` digits, which for COMP-5 or TRUNC(BIN)
88    /// are as many as the item's halfword, fullword or doubleword holds.
89    Digits { place: P, digits: u32, signed: bool },
90    /// Floating-point, pointer, index and object-reference items: the place, then the abend.
91    Refused { place: P, abend: AbendId },
92    /// A literal or figurative constant as DISPLAY shows it; a numeric literal as written.
93    Text(SymId),
94    /// FUNCTION, LENGTH OF or ADDRESS OF, by the value's kind.
95    Value(O),
96}
97
98/// SEARCH ALL's binary search. The op returns Arm(0) on an occurrence whose keys equal their WHEN
99/// terms, for a Branch on the whole condition, and Arm(1) when the search ends without one.
100#[derive(Clone, Debug, PartialEq, Eq)]
101pub struct SearchAllPlan<P = PlaceId, V = Comparand, N = Count> {
102    /// The table's first index, stored by `store` at each occurrence tried.
103    pub index: P,
104    pub store: StorePlan,
105    pub count: N,
106    /// The keys the WHEN condition tests for equality, in the table's KEY order.
107    pub keys: Vec<SearchKey<V>>,
108}
109
110/// `key` as the WHEN term names it, and the `value` it must equal.
111#[derive(Clone, Copy, Debug, PartialEq, Eq)]
112pub struct SearchKey<V = Comparand> {
113    pub ascending: bool,
114    pub key: V,
115    pub value: V,
116    pub how: Compare,
117}
118
119#[derive(Clone, Debug, PartialEq, Eq)]
120pub struct FunctionPlan {
121    pub func: Func,
122    pub args: Vec<ExprId>,
123    pub side: Option<TrimSide>,
124    pub refmod: Option<RefMod>,
125    pub at: DebugId,
126}
127
128#[derive(Clone, Copy, Debug, PartialEq, Eq)]
129pub enum Func {
130    Char,
131    Ord,
132    NationalOf,
133    Length,
134    UpperCase,
135    LowerCase,
136    Reverse,
137    CurrentDate,
138    Numval,
139    NumvalC,
140    Trim,
141    Mod,
142    Rem,
143    Integer,
144    IntegerPart,
145    Abs,
146    Min,
147    Max,
148    IntegerOfDate,
149    DateOfInteger,
150}
151
152#[derive(Clone, Copy, Debug, PartialEq, Eq)]
153pub enum TrimSide {
154    Leading,
155    Trailing,
156}
157
158/// `args` and `returning` carry each Java type signature. The op evaluates the method name, then the
159/// receiver, then each argument, and returns Arm(1) when no method matches and ON EXCEPTION is
160/// written, Arm(0) otherwise, or Next when neither phrase is written. `returning` is moved by the
161/// kind of the value the method returns.
162#[derive(Clone, Debug, PartialEq, Eq)]
163pub struct InvokePlan {
164    pub receiver: Receiver,
165    pub method: MethodName,
166    pub args: Vec<(Operand, SymId)>,
167    pub returning: Option<(PlaceId, SymId)>,
168    pub on_exception: bool,
169    pub not_on_exception: bool,
170}
171
172/// `Class` is a REPOSITORY class-name: `name` as written, which messages give, and `external`, which
173/// finds the class.
174#[derive(Clone, Copy, Debug, PartialEq, Eq)]
175pub enum Receiver {
176    SelfRef,
177    Super,
178    Class { name: SymId, external: SymId },
179    Object(PlaceId),
180}
181
182#[derive(Clone, Copy, Debug, PartialEq, Eq)]
183pub enum MethodName {
184    New,
185    Named(SymId),
186    Dynamic(PlaceId),
187}
188
189codec_enum!(MovePlan {
190    Alnum { image, justified } = 0,
191    AlnumEdited { image, edit, positions } = 1,
192    National(from) = 2,
193    Numeric { from, store } = 3,
194    Float { from, precision } = 4,
195    Address = 5,
196    Index = 6,
197    Refused(abend) = 7,
198});
199codec_enum!(Image { Bytes = 0, All = 1, Figurative = 2, Digits { digits } = 3 });
200codec_enum!(NationalFrom { Units = 0, Decoded = 1, Figurative = 2 });
201codec_enum!(NumericFrom {
202    Value = 0,
203    PackedCopy = 1,
204    Float = 2,
205    Zero = 3,
206    Fill = 4,
207    Zoned = 5,
208    DeEdit { edit, digits, scale } = 6,
209});
210codec_enum!(FloatFrom { Float = 0, Fixed = 1, Zero = 2 });
211codec_struct!(InitPlan { fields });
212codec_struct!(InitField { offset, len, value, store });
213codec_struct!(DisplayPlan { items, no_advancing });
214codec_enum!(DisplayItem {
215    Bytes(place) = 0,
216    National(place) = 1,
217    Digits { place, digits, signed } = 2,
218    Refused { place, abend } = 3,
219    Text(text) = 4,
220    Value(value) = 5,
221});
222codec_struct!(SearchAllPlan { index, store, count, keys });
223codec_struct!(SearchKey { ascending, key, value, how });
224codec_struct!(FunctionPlan { func, args, side, refmod, at });
225codec_enum!(Func {
226    Char = 0,
227    Ord = 1,
228    NationalOf = 2,
229    Length = 3,
230    UpperCase = 4,
231    LowerCase = 5,
232    Reverse = 6,
233    CurrentDate = 7,
234    Numval = 8,
235    NumvalC = 9,
236    Trim = 10,
237    Mod = 11,
238    Rem = 12,
239    Integer = 13,
240    IntegerPart = 14,
241    Abs = 15,
242    Min = 16,
243    Max = 17,
244    IntegerOfDate = 18,
245    DateOfInteger = 19,
246});
247codec_enum!(TrimSide { Leading = 0, Trailing = 1 });
248codec_struct!(InvokePlan { receiver, method, args, returning, on_exception, not_on_exception });
249codec_enum!(Receiver { SelfRef = 0, Super = 1, Class { name, external } = 2, Object(place) = 3 });
250codec_enum!(MethodName { New = 0, Named(name) = 1, Dynamic(place) = 2 });
251
252macro_rules! placeholder {
253    ($($ty:ident: $doc:literal,)*) => {$(
254        #[doc = $doc]
255        #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
256        pub enum $ty {
257            #[default]
258            Placeholder,
259        }
260
261        codec_enum!($ty { Placeholder = 0 });
262    )*};
263}
264
265placeholder! {
266    FileOp: "A file verb with its phrases, §9.4; waits for `OpenMode`, `StartRel` and `FileDesc`.",
267    FileDesc: "A file's declaration, §9.4; not defined yet.",
268    SortPlan: "SORT or MERGE, §9.6; waits for `SortKey` and `Fastsrt`.",
269    ReleasePlan: "RELEASE, §9.6; not defined yet.",
270    ReturnPlan: "RETURN, §9.6; not defined yet.",
271    ReportOp: "INITIATE, GENERATE, TERMINATE or SUPPRESS, §9.6; not defined yet.",
272    CicsCommand: "An EXEC CICS command, §9.5; waits for the CICS code to move into rt.",
273}