use super::{AbendId, Comparand, Compare, Count, DebugId, IntExpr, Operand, PlaceId, RefMod, StorePlan, SymId};
use crate::vocab::Figurative;
use crate::{codec_enum, codec_struct};
use zarch::hfp::Precision;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MovePlan {
Alnum { image: Image, justified: bool },
AlnumEdited { image: Image, edit: u32, positions: u32 },
National(NationalFrom),
Numeric { from: NumericFrom, store: StorePlan },
Float { from: FloatFrom, precision: Precision },
Address,
Index,
Refused(AbendId),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Image {
Bytes,
All,
Figurative,
Digits { digits: u32 },
Stored,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NationalFrom {
Units,
Decoded,
Figurative,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NumericFrom {
Value,
PackedCopy,
Float,
Zero,
Fill,
Zoned,
DeEdit { edit: u32, digits: u32, scale: u32 },
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FloatFrom {
Float,
Fixed,
Zero,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct InitPlan {
pub fields: Vec<InitField>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct InitField {
pub offset: u32,
pub len: u32,
pub value: Figurative,
pub store: MovePlan,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DisplayPlan<P = PlaceId, O = Operand> {
pub items: Vec<DisplayItem<P, O>>,
pub no_advancing: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DisplayItem<P = PlaceId, O = Operand> {
Bytes(P),
National(P),
Digits { place: P, digits: u32, signed: bool },
Refused { place: P, abend: AbendId },
Text(SymId),
Value(O),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SearchAllPlan<P = PlaceId, V = Comparand, N = Count> {
pub index: P,
pub store: StorePlan,
pub count: N,
pub keys: Vec<SearchKey<V>>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SearchKey<V = Comparand> {
pub ascending: bool,
pub key: V,
pub value: V,
pub how: Compare,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FunctionPlan {
pub func: Func,
pub args: Vec<Argument>,
pub integer: Option<IntExpr>,
pub side: Option<TrimSide>,
pub refmod: Option<RefMod>,
pub arity: Option<AbendId>,
pub at: DebugId,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Argument {
Value(Comparand),
All { element: PlaceId, all: Vec<(u32, Count)> },
}
macro_rules! functions {
($($variant:ident = $tag:literal, $name:literal, $min:literal ..= $max:expr;)*) => {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Func {
$($variant,)*
}
impl Func {
pub const ALL: &'static [Func] = &[$(Func::$variant,)*];
pub fn name(self) -> &'static str {
match self {
$(Func::$variant => $name,)*
}
}
pub fn named(name: &str) -> Option<Func> {
match name {
$($name => Some(Func::$variant),)*
_ => None,
}
}
pub fn arity(self) -> ::core::ops::RangeInclusive<usize> {
match self {
$(Func::$variant => $min..=$max,)*
}
}
}
codec_enum!(Func { $($variant = $tag,)* });
};
}
functions! {
Char = 0, "CHAR", 1..=1;
Ord = 1, "ORD", 1..=1;
NationalOf = 2, "NATIONAL-OF", 1..=2;
Length = 3, "LENGTH", 1..=1;
UpperCase = 4, "UPPER-CASE", 1..=1;
LowerCase = 5, "LOWER-CASE", 1..=1;
Reverse = 6, "REVERSE", 1..=1;
CurrentDate = 7, "CURRENT-DATE", 0..=0;
Numval = 8, "NUMVAL", 1..=2;
NumvalC = 9, "NUMVAL-C", 1..=2;
Trim = 10, "TRIM", 1..=1;
Mod = 11, "MOD", 2..=2;
Rem = 12, "REM", 2..=2;
Integer = 13, "INTEGER", 1..=1;
IntegerPart = 14, "INTEGER-PART", 1..=1;
Abs = 15, "ABS", 1..=1;
Min = 16, "MIN", 1..=usize::MAX;
Max = 17, "MAX", 1..=usize::MAX;
IntegerOfDate = 18, "INTEGER-OF-DATE", 1..=1;
DateOfInteger = 19, "DATE-OF-INTEGER", 1..=1;
Random = 20, "RANDOM", 0..=1;
Acos = 21, "ACOS", 1..=1;
Annuity = 22, "ANNUITY", 2..=2;
Asin = 23, "ASIN", 1..=1;
Atan = 24, "ATAN", 1..=1;
BitOf = 25, "BIT-OF", 1..=1;
BitToChar = 26, "BIT-TO-CHAR", 1..=1;
ByteLength = 27, "BYTE-LENGTH", 1..=1;
Cos = 28, "COS", 1..=1;
DateToYyyymmdd = 29, "DATE-TO-YYYYMMDD", 1..=2;
DayOfInteger = 30, "DAY-OF-INTEGER", 1..=1;
DayToYyyyddd = 31, "DAY-TO-YYYYDDD", 1..=2;
DisplayOf = 32, "DISPLAY-OF", 1..=2;
E = 33, "E", 0..=0;
Exp = 34, "EXP", 1..=1;
Exp10 = 35, "EXP10", 1..=1;
Factorial = 36, "FACTORIAL", 1..=1;
FormattedCurrentDate = 37, "FORMATTED-CURRENT-DATE", 1..=1;
FormattedDate = 38, "FORMATTED-DATE", 2..=2;
FormattedDatetime = 39, "FORMATTED-DATETIME", 3..=4;
FormattedTime = 40, "FORMATTED-TIME", 2..=3;
HexOf = 41, "HEX-OF", 1..=1;
HexToChar = 42, "HEX-TO-CHAR", 1..=1;
IntegerOfDay = 43, "INTEGER-OF-DAY", 1..=1;
IntegerOfFormattedDate = 44, "INTEGER-OF-FORMATTED-DATE", 2..=2;
Log = 45, "LOG", 1..=1;
Log10 = 46, "LOG10", 1..=1;
Mean = 47, "MEAN", 1..=usize::MAX;
Median = 48, "MEDIAN", 1..=usize::MAX;
Midrange = 49, "MIDRANGE", 1..=usize::MAX;
NumvalF = 50, "NUMVAL-F", 1..=1;
OrdMax = 51, "ORD-MAX", 1..=usize::MAX;
OrdMin = 52, "ORD-MIN", 1..=usize::MAX;
Pi = 53, "PI", 0..=0;
PresentValue = 54, "PRESENT-VALUE", 2..=usize::MAX;
Range = 55, "RANGE", 1..=usize::MAX;
SecondsFromFormattedTime = 56, "SECONDS-FROM-FORMATTED-TIME", 2..=2;
SecondsPastMidnight = 57, "SECONDS-PAST-MIDNIGHT", 0..=0;
Sign = 58, "SIGN", 1..=1;
Sin = 59, "SIN", 1..=1;
Sqrt = 60, "SQRT", 1..=1;
StandardDeviation = 61, "STANDARD-DEVIATION", 1..=usize::MAX;
Sum = 62, "SUM", 1..=usize::MAX;
Tan = 63, "TAN", 1..=1;
TestDateYyyymmdd = 64, "TEST-DATE-YYYYMMDD", 1..=1;
TestDayYyyyddd = 65, "TEST-DAY-YYYYDDD", 1..=1;
TestFormattedDatetime = 66, "TEST-FORMATTED-DATETIME", 2..=2;
TestNumval = 67, "TEST-NUMVAL", 1..=1;
TestNumvalC = 68, "TEST-NUMVAL-C", 1..=2;
TestNumvalF = 69, "TEST-NUMVAL-F", 1..=1;
Uuid4 = 70, "UUID4", 0..=0;
Variance = 71, "VARIANCE", 1..=usize::MAX;
YearToYyyy = 72, "YEAR-TO-YYYY", 1..=2;
WhenCompiled = 73, "WHEN-COMPILED", 0..=0;
Ulength = 74, "ULENGTH", 1..=1;
Upos = 75, "UPOS", 2..=2;
Usubstr = 76, "USUBSTR", 3..=3;
Usupplementary = 77, "USUPPLEMENTARY", 1..=1;
Uvalid = 78, "UVALID", 1..=1;
Uwidth = 79, "UWIDTH", 2..=2;
CombinedDatetime = 80, "COMBINED-DATETIME", 2..=2;
ContentOf = 81, "CONTENT-OF", 1..=1;
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TrimSide {
Leading,
Trailing,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct InvokePlan<P = PlaceId, O = Operand, S = SymId> {
pub receiver: Receiver<P, S>,
pub method: MethodName<P, S>,
pub args: Vec<(O, S)>,
pub returning: Option<(P, S)>,
pub on_exception: bool,
pub not_on_exception: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Receiver<P = PlaceId, S = SymId> {
SelfRef,
Super,
Class { name: S, external: S },
Object(P),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MethodName<P = PlaceId, S = SymId> {
New,
Named(S),
Dynamic(P),
}
codec_enum!(MovePlan {
Alnum { image, justified } = 0,
AlnumEdited { image, edit, positions } = 1,
National(from) = 2,
Numeric { from, store } = 3,
Float { from, precision } = 4,
Address = 5,
Index = 6,
Refused(abend) = 7,
});
codec_enum!(Image { Bytes = 0, All = 1, Figurative = 2, Digits { digits } = 3, Stored = 4 });
codec_enum!(NationalFrom { Units = 0, Decoded = 1, Figurative = 2 });
codec_enum!(NumericFrom {
Value = 0,
PackedCopy = 1,
Float = 2,
Zero = 3,
Fill = 4,
Zoned = 5,
DeEdit { edit, digits, scale } = 6,
});
codec_enum!(FloatFrom { Float = 0, Fixed = 1, Zero = 2 });
codec_struct!(InitPlan { fields });
codec_struct!(InitField { offset, len, value, store });
codec_struct!(DisplayPlan { items, no_advancing });
codec_enum!(DisplayItem {
Bytes(place) = 0,
National(place) = 1,
Digits { place, digits, signed } = 2,
Refused { place, abend } = 3,
Text(text) = 4,
Value(value) = 5,
});
codec_struct!(SearchAllPlan { index, store, count, keys });
codec_struct!(SearchKey { ascending, key, value, how });
codec_struct!(FunctionPlan { func, args, integer, side, refmod, arity, at });
codec_enum!(Argument { Value(value) = 0, All { element, all } = 1 });
codec_enum!(TrimSide { Leading = 0, Trailing = 1 });
codec_struct!(InvokePlan { receiver, method, args, returning, on_exception, not_on_exception });
codec_enum!(Receiver { SelfRef = 0, Super = 1, Class { name, external } = 2, Object(place) = 3 });
codec_enum!(MethodName { New = 0, Named(name) = 1, Dynamic(place) = 2 });