1use super::{AbendId, Comparand, Compare, Count, DebugId, IntExpr, 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 Stored,
31}
32
33#[derive(Clone, Copy, Debug, PartialEq, Eq)]
34pub enum NationalFrom {
35 Units,
36 Decoded,
37 Figurative,
38}
39
40#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41pub enum NumericFrom {
42 Value,
45 PackedCopy,
47 Float,
48 Zero,
49 Fill,
51 Zoned,
54 DeEdit { edit: u32, digits: u32, scale: u32 },
55}
56
57#[derive(Clone, Copy, Debug, PartialEq, Eq)]
58pub enum FloatFrom {
59 Float,
60 Fixed,
61 Zero,
62}
63
64#[derive(Clone, Debug, PartialEq, Eq)]
66pub struct InitPlan {
67 pub fields: Vec<InitField>,
68}
69
70#[derive(Clone, Copy, Debug, PartialEq, Eq)]
73pub struct InitField {
74 pub offset: u32,
75 pub len: u32,
76 pub value: Figurative,
77 pub store: MovePlan,
78}
79
80#[derive(Clone, Debug, PartialEq, Eq)]
82pub struct DisplayPlan<P = PlaceId, O = Operand> {
83 pub items: Vec<DisplayItem<P, O>>,
84 pub no_advancing: bool,
85}
86
87#[derive(Clone, Copy, Debug, PartialEq, Eq)]
88pub enum DisplayItem<P = PlaceId, O = Operand> {
89 Bytes(P),
91 National(P),
92 Digits { place: P, digits: u32, signed: bool },
95 Refused { place: P, abend: AbendId },
97 Text(SymId),
100 Value(O),
102}
103
104#[derive(Clone, Debug, PartialEq, Eq)]
107pub struct SearchAllPlan<P = PlaceId, V = Comparand, N = Count> {
108 pub index: P,
110 pub store: StorePlan,
111 pub count: N,
112 pub keys: Vec<SearchKey<V>>,
114}
115
116#[derive(Clone, Copy, Debug, PartialEq, Eq)]
118pub struct SearchKey<V = Comparand> {
119 pub ascending: bool,
120 pub key: V,
121 pub value: V,
122 pub how: Compare,
123}
124
125#[derive(Clone, Debug, PartialEq, Eq)]
136pub struct FunctionPlan {
137 pub func: Func,
138 pub args: Vec<Argument>,
139 pub integer: Option<IntExpr>,
140 pub side: Option<TrimSide>,
142 pub refmod: Option<RefMod>,
143 pub arity: Option<AbendId>,
144 pub at: DebugId,
145}
146
147#[derive(Clone, Debug, PartialEq, Eq)]
149pub enum Argument {
150 Value(Comparand),
151 All { element: PlaceId, all: Vec<(u32, Count)> },
156}
157
158macro_rules! functions {
161 ($($variant:ident = $tag:literal, $name:literal, $min:literal ..= $max:expr;)*) => {
162 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
163 pub enum Func {
164 $($variant,)*
165 }
166
167 impl Func {
168 pub const ALL: &'static [Func] = &[$(Func::$variant,)*];
169
170 pub fn name(self) -> &'static str {
171 match self {
172 $(Func::$variant => $name,)*
173 }
174 }
175
176 pub fn named(name: &str) -> Option<Func> {
177 match name {
178 $($name => Some(Func::$variant),)*
179 _ => None,
180 }
181 }
182
183 pub fn arity(self) -> ::core::ops::RangeInclusive<usize> {
185 match self {
186 $(Func::$variant => $min..=$max,)*
187 }
188 }
189 }
190
191 codec_enum!(Func { $($variant = $tag,)* });
192 };
193}
194
195functions! {
196 Char = 0, "CHAR", 1..=1;
197 Ord = 1, "ORD", 1..=1;
198 NationalOf = 2, "NATIONAL-OF", 1..=2;
199 Length = 3, "LENGTH", 1..=1;
200 UpperCase = 4, "UPPER-CASE", 1..=1;
201 LowerCase = 5, "LOWER-CASE", 1..=1;
202 Reverse = 6, "REVERSE", 1..=1;
203 CurrentDate = 7, "CURRENT-DATE", 0..=0;
204 Numval = 8, "NUMVAL", 1..=2;
205 NumvalC = 9, "NUMVAL-C", 1..=2;
206 Trim = 10, "TRIM", 1..=1;
207 Mod = 11, "MOD", 2..=2;
208 Rem = 12, "REM", 2..=2;
209 Integer = 13, "INTEGER", 1..=1;
210 IntegerPart = 14, "INTEGER-PART", 1..=1;
211 Abs = 15, "ABS", 1..=1;
212 Min = 16, "MIN", 1..=usize::MAX;
213 Max = 17, "MAX", 1..=usize::MAX;
214 IntegerOfDate = 18, "INTEGER-OF-DATE", 1..=1;
215 DateOfInteger = 19, "DATE-OF-INTEGER", 1..=1;
216 Random = 20, "RANDOM", 0..=1;
217 Acos = 21, "ACOS", 1..=1;
218 Annuity = 22, "ANNUITY", 2..=2;
219 Asin = 23, "ASIN", 1..=1;
220 Atan = 24, "ATAN", 1..=1;
221 BitOf = 25, "BIT-OF", 1..=1;
222 BitToChar = 26, "BIT-TO-CHAR", 1..=1;
223 ByteLength = 27, "BYTE-LENGTH", 1..=1;
224 Cos = 28, "COS", 1..=1;
225 DateToYyyymmdd = 29, "DATE-TO-YYYYMMDD", 1..=2;
226 DayOfInteger = 30, "DAY-OF-INTEGER", 1..=1;
227 DayToYyyyddd = 31, "DAY-TO-YYYYDDD", 1..=2;
228 DisplayOf = 32, "DISPLAY-OF", 1..=2;
229 E = 33, "E", 0..=0;
230 Exp = 34, "EXP", 1..=1;
231 Exp10 = 35, "EXP10", 1..=1;
232 Factorial = 36, "FACTORIAL", 1..=1;
233 FormattedCurrentDate = 37, "FORMATTED-CURRENT-DATE", 1..=1;
234 FormattedDate = 38, "FORMATTED-DATE", 2..=2;
235 FormattedDatetime = 39, "FORMATTED-DATETIME", 3..=4;
236 FormattedTime = 40, "FORMATTED-TIME", 2..=3;
237 HexOf = 41, "HEX-OF", 1..=1;
238 HexToChar = 42, "HEX-TO-CHAR", 1..=1;
239 IntegerOfDay = 43, "INTEGER-OF-DAY", 1..=1;
240 IntegerOfFormattedDate = 44, "INTEGER-OF-FORMATTED-DATE", 2..=2;
241 Log = 45, "LOG", 1..=1;
242 Log10 = 46, "LOG10", 1..=1;
243 Mean = 47, "MEAN", 1..=usize::MAX;
244 Median = 48, "MEDIAN", 1..=usize::MAX;
245 Midrange = 49, "MIDRANGE", 1..=usize::MAX;
246 NumvalF = 50, "NUMVAL-F", 1..=1;
247 OrdMax = 51, "ORD-MAX", 1..=usize::MAX;
248 OrdMin = 52, "ORD-MIN", 1..=usize::MAX;
249 Pi = 53, "PI", 0..=0;
250 PresentValue = 54, "PRESENT-VALUE", 2..=usize::MAX;
251 Range = 55, "RANGE", 1..=usize::MAX;
252 SecondsFromFormattedTime = 56, "SECONDS-FROM-FORMATTED-TIME", 2..=2;
253 SecondsPastMidnight = 57, "SECONDS-PAST-MIDNIGHT", 0..=0;
254 Sign = 58, "SIGN", 1..=1;
255 Sin = 59, "SIN", 1..=1;
256 Sqrt = 60, "SQRT", 1..=1;
257 StandardDeviation = 61, "STANDARD-DEVIATION", 1..=usize::MAX;
258 Sum = 62, "SUM", 1..=usize::MAX;
259 Tan = 63, "TAN", 1..=1;
260 TestDateYyyymmdd = 64, "TEST-DATE-YYYYMMDD", 1..=1;
261 TestDayYyyyddd = 65, "TEST-DAY-YYYYDDD", 1..=1;
262 TestFormattedDatetime = 66, "TEST-FORMATTED-DATETIME", 2..=2;
263 TestNumval = 67, "TEST-NUMVAL", 1..=1;
264 TestNumvalC = 68, "TEST-NUMVAL-C", 1..=2;
265 TestNumvalF = 69, "TEST-NUMVAL-F", 1..=1;
266 Uuid4 = 70, "UUID4", 0..=0;
267 Variance = 71, "VARIANCE", 1..=usize::MAX;
268 YearToYyyy = 72, "YEAR-TO-YYYY", 1..=2;
269 WhenCompiled = 73, "WHEN-COMPILED", 0..=0;
270 Ulength = 74, "ULENGTH", 1..=1;
271 Upos = 75, "UPOS", 2..=2;
272 Usubstr = 76, "USUBSTR", 3..=3;
273 Usupplementary = 77, "USUPPLEMENTARY", 1..=1;
274 Uvalid = 78, "UVALID", 1..=1;
275 Uwidth = 79, "UWIDTH", 2..=2;
276 CombinedDatetime = 80, "COMBINED-DATETIME", 2..=2;
277 ContentOf = 81, "CONTENT-OF", 1..=1;
278}
279
280#[derive(Clone, Copy, Debug, PartialEq, Eq)]
281pub enum TrimSide {
282 Leading,
283 Trailing,
284}
285
286#[derive(Clone, Debug, PartialEq, Eq)]
291pub struct InvokePlan<P = PlaceId, O = Operand, S = SymId> {
292 pub receiver: Receiver<P, S>,
293 pub method: MethodName<P, S>,
294 pub args: Vec<(O, S)>,
295 pub returning: Option<(P, S)>,
296 pub on_exception: bool,
297 pub not_on_exception: bool,
298}
299
300#[derive(Clone, Copy, Debug, PartialEq, Eq)]
303pub enum Receiver<P = PlaceId, S = SymId> {
304 SelfRef,
305 Super,
306 Class { name: S, external: S },
307 Object(P),
308}
309
310#[derive(Clone, Copy, Debug, PartialEq, Eq)]
311pub enum MethodName<P = PlaceId, S = SymId> {
312 New,
313 Named(S),
314 Dynamic(P),
315}
316
317codec_enum!(MovePlan {
318 Alnum { image, justified } = 0,
319 AlnumEdited { image, edit, positions } = 1,
320 National(from) = 2,
321 Numeric { from, store } = 3,
322 Float { from, precision } = 4,
323 Address = 5,
324 Index = 6,
325 Refused(abend) = 7,
326});
327codec_enum!(Image { Bytes = 0, All = 1, Figurative = 2, Digits { digits } = 3, Stored = 4 });
328codec_enum!(NationalFrom { Units = 0, Decoded = 1, Figurative = 2 });
329codec_enum!(NumericFrom {
330 Value = 0,
331 PackedCopy = 1,
332 Float = 2,
333 Zero = 3,
334 Fill = 4,
335 Zoned = 5,
336 DeEdit { edit, digits, scale } = 6,
337});
338codec_enum!(FloatFrom { Float = 0, Fixed = 1, Zero = 2 });
339codec_struct!(InitPlan { fields });
340codec_struct!(InitField { offset, len, value, store });
341codec_struct!(DisplayPlan { items, no_advancing });
342codec_enum!(DisplayItem {
343 Bytes(place) = 0,
344 National(place) = 1,
345 Digits { place, digits, signed } = 2,
346 Refused { place, abend } = 3,
347 Text(text) = 4,
348 Value(value) = 5,
349});
350codec_struct!(SearchAllPlan { index, store, count, keys });
351codec_struct!(SearchKey { ascending, key, value, how });
352codec_struct!(FunctionPlan { func, args, integer, side, refmod, arity, at });
353codec_enum!(Argument { Value(value) = 0, All { element, all } = 1 });
354codec_enum!(TrimSide { Leading = 0, Trailing = 1 });
355codec_struct!(InvokePlan { receiver, method, args, returning, on_exception, not_on_exception });
356codec_enum!(Receiver { SelfRef = 0, Super = 1, Class { name, external } = 2, Object(place) = 3 });
357codec_enum!(MethodName { New = 0, Named(name) = 1, Dynamic(place) = 2 });