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