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