1use crate::abend::{AbendCode, Ending, FileStatus, Signal};
4use crate::module::ModuleError;
5use crate::module::codec::{Decode, Encode, Reader, Writer};
6use crate::picture::Sym;
7use crate::sql::HostType;
8use crate::storage::Kind;
9use crate::vocab::{AcceptFrom, BinOp, Figurative, InspectMode, RelOp, SignClause, SignPosition};
10use crate::{codec_enum, codec_struct};
11use numeric::precision::{Fixed, Places};
12use numeric::options::{Compile, FastsrtAdvPrint, Stop, Warnings};
13use numeric::{Arith, Numproc, Options, SortKeys, Trunc, TruncCheck};
14use zarch::check::ProgramCheck;
15use zarch::ebcdic::CodePage;
16use zarch::hfp::Precision;
17use zarch::wide::U256;
18
19codec_enum!(Kind {
20 Group = 0,
21 Alnum { justified } = 1,
22 National = 2,
23 Zoned { digits, scale, signed, sign } = 3,
24 Packed { digits, scale, signed } = 4,
25 Binary { digits, scale, signed, native } = 5,
26 Float(precision) = 6,
27 NumericEdited { edit, digits, scale, blank_when_zero } = 7,
28 AlnumEdited { edit } = 8,
29 Pointer = 9,
30 Index = 10,
31 ObjectReference = 11,
32 ProgramPointer = 12,
33});
34codec_struct!(SignClause { position, separate });
35codec_enum!(SignPosition { Leading = 0, Trailing = 1 });
36codec_enum!(Figurative { Zero = 0, Space = 1, HighValue = 2, LowValue = 3, Quote = 4, Null = 5 });
37codec_enum!(BinOp { Add = 0, Sub = 1, Mul = 2, Div = 3, Pow = 4 });
38codec_enum!(RelOp { Eq = 0, Ne = 1, Lt = 2, Le = 3, Gt = 4, Ge = 5 });
39codec_enum!(AcceptFrom {
40 Sysin = 0,
41 Date { four_digit_year } = 1,
42 Day { four_digit_year } = 2,
43 DayOfWeek = 3,
44 Time = 4,
45});
46codec_enum!(InspectMode { Characters = 0, All = 1, Leading = 2, First = 3 });
47codec_enum!(HostType {
48 SmallInt { signed } = 0,
49 Integer { signed } = 1,
50 BigInt { signed } = 2,
51 Decimal { digits, scale, signed } = 3,
52 Zoned { digits, scale, signed, sign } = 4,
53 Real = 5,
54 Double = 6,
55 Char(len) = 7,
56 VarChar(max) = 8,
57 Structure(members) = 9,
58});
59codec_enum!(Sym {
60 Nine = 0,
61 Z = 1,
62 Star = 2,
63 FloatLead(c) = 3,
64 Float(c) = 4,
65 Sign(c) = 5,
66 Currency = 6,
67 Cr = 7,
68 Db = 8,
69 Point = 9,
70 Implied = 10,
71 Insert(c) = 11,
72 Char = 12,
73});
74codec_enum!(Precision { Short = 0, Long = 1, Extended = 2 });
75codec_enum!(ProgramCheck {
76 Specification = 0,
77 Data = 1,
78 FixedPointOverflow = 2,
79 FixedPointDivide = 3,
80 DecimalOverflow = 4,
81 DecimalDivide = 5,
82 HfpExponentOverflow = 6,
83 HfpExponentUnderflow = 7,
84 HfpSignificance = 8,
85 HfpDivide = 9,
86});
87
88codec_enum!(Ending { Goback = 0, StopRun = 1, EndOfProgram = 2 });
89codec_enum!(AbendCode {
90 Check(check) = 0,
91 Protection = 1,
92 ModuleNotFound = 2,
93 Io(status) = 3,
94 Cics(code) = 4,
95 User(code) = 5,
96 Ironwork = 6,
97 Exec = 7,
98 Sql = 8,
99 SqlReplay = 9,
100 Java = 10,
101 Signal(signal) = 11,
102});
103codec_enum!(Signal { StopRun = 0, GoBack = 1, SortStopped = 2, ClosedOutput = 3, DeclarativeExit = 4 });
104codec_enum!(FileStatus {
105 Success = 0,
106 SuccessDuplicate = 1,
107 SuccessWrongLength = 2,
108 SuccessOptional = 3,
109 AtEnd = 4,
110 RelativeKeyOverflow = 5,
111 SequenceError = 6,
112 DuplicateKey = 7,
113 NotFound = 8,
114 BoundaryViolation = 9,
115 PermanentError = 10,
116 FileNotFound = 11,
117 OpenModeUnsupported = 12,
118 AlreadyOpen = 13,
119 NotOpen = 14,
120 NoPriorRead = 15,
121 RecordLengthChanged = 16,
122 NoNextRecord = 17,
123 NotOpenInput = 18,
124 NotOpenOutput = 19,
125 NotOpenInputOutput = 20,
126});
127
128codec_struct!(Options {
129 arith, trunc, numproc, codepage, trunc_check, fastsrt, fastsrt_adv_print, sort_keys, adv, thread, dll, rent, dbcs,
130 warnings, compile, dynam, debug,
131} check options_valid);
132codec_enum!(Arith { Compat = 0, Extend = 1 });
133codec_enum!(Trunc { Std = 0, Opt = 1, Bin = 2 });
134codec_enum!(Numproc { Nopfd = 0, Pfd = 1 });
135codec_enum!(TruncCheck { Report = 0, Silent = 1 });
136codec_enum!(SortKeys { Dfsort = 0, Strict = 1 });
137codec_enum!(FastsrtAdvPrint { Exclude = 0, Include = 1 });
138codec_enum!(Warnings { Proceed = 0, Block = 1 });
139codec_enum!(Compile { Full = 0, Until(stop) = 1, SyntaxOnly = 2 });
140codec_enum!(Stop { W = 0, E = 1, S = 2 });
141
142fn options_valid(options: &Options) -> Result<(), String> {
144 match CodePage::by_ccsid(options.codepage) {
145 Some(_) => Ok(()),
146 None => Err(format!("CODEPAGE({}) is not a page the tables carry", options.codepage)),
147 }
148}
149
150codec_struct!(Fixed { negative, magnitude, places });
151codec_struct!(Places { int, dec });
152
153impl Encode for U256 {
155 fn encode(&self, w: &mut Writer) {
156 [self.lo as u64, (self.lo >> 64) as u64, self.hi as u64, (self.hi >> 64) as u64].encode(w);
157 }
158}
159
160impl Decode for U256 {
161 fn decode(r: &mut Reader<'_>) -> Result<Self, ModuleError> {
162 let [a, b, c, d] = <[u64; 4]>::decode(r)?;
163 let limbs = |low: u64, high: u64| u128::from(low) | u128::from(high) << 64;
164 Ok(U256 { hi: limbs(c, d), lo: limbs(a, b) })
165 }
166}