Skip to main content

ironwork_rt/lir/
value.rs

1//! Values, expressions and conditions (lir.md ยง6).
2
3use super::{AbendId, CondId, ConstId, ExprId, FunctionId, Mode, Odo, PlaceId, TempId};
4use crate::codec_enum;
5use crate::vocab::{BinOp, Figurative, RelOp};
6use numeric::precision::Fixed;
7
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum Operand {
10    Load(PlaceId),
11    Const(ConstId),
12    LengthOf(PlaceId),
13    AddressOf(PlaceId),
14    Function(FunctionId),
15}
16
17#[derive(Clone, Debug, PartialEq, Eq)]
18pub enum Const {
19    Bytes(Vec<u8>),
20    National(Vec<u8>),
21    Number(Fixed),
22    Figurative(Figurative),
23    All(Vec<u8>),
24}
25
26/// `Fixed` locates each place of `prepass` before it evaluates `expr`, as the walker's dmax pass
27/// does; static places are left out.
28#[derive(Clone, Debug, PartialEq, Eq)]
29pub enum IntExpr {
30    Const(i64),
31    Item(PlaceId),
32    Fixed { expr: ExprId, dmax: u32, prepass: Vec<PlaceId> },
33}
34
35#[derive(Clone, Debug, PartialEq, Eq)]
36pub enum Expr {
37    Operand(Operand),
38    Neg(ExprId),
39    Bin(ExprId, BinOp, ExprId),
40    /// An exponent from 0 to 31, else abend IRONWORK.
41    Pow(ExprId, IntExpr),
42}
43
44#[derive(Clone, Debug, PartialEq, Eq)]
45pub enum Cond {
46    Rel { a: Comparand, op: RelOp, b: Comparand, how: Compare },
47    Class { place: PlaceId, test: ByteClass },
48    Sign { value: Comparand, test: SignTest },
49    /// A level-88 name: equal to any value, or within any THRU pair.
50    Name { subject: PlaceId, values: Vec<(ConstId, Option<ConstId>)>, how: Compare },
51    Not(CondId),
52    And(CondId, CondId),
53    Or(CondId, CondId),
54    Counter(TempId),
55    InTable { index: PlaceId, count: Count },
56    Sql(SqlTest),
57}
58
59/// `Expr` locates each place of `prepass` (the float test's, then for `Mode::Fixed` the dmax pass's,
60/// static ones left out) before it evaluates `expr` in `mode`.
61#[derive(Clone, Debug, PartialEq, Eq)]
62pub enum Comparand {
63    Operand(Operand),
64    Expr { expr: ExprId, dmax: u32, mode: Mode, prepass: Vec<PlaceId> },
65}
66
67#[derive(Clone, Copy, Debug, PartialEq, Eq)]
68pub enum Compare {
69    PackedPfd,
70    Address,
71    Float,
72    Fixed,
73    National,
74    Alphanumeric,
75    Refused(AbendId),
76    /// Two addresses, one side an object reference: equal when both identify the same object, else
77    /// less. Each side is looked up, the first first, and one that was freed or never given abends.
78    References,
79}
80
81#[derive(Clone, Copy, Debug, PartialEq, Eq)]
82pub enum ByteClass {
83    Packed { signed: bool },
84    Zoned { signed: bool },
85    Digits,
86    Alphabetic,
87}
88
89#[derive(Clone, Copy, Debug, PartialEq, Eq)]
90pub enum SignTest {
91    Positive,
92    Negative,
93    Zero,
94}
95
96#[derive(Clone, Debug, PartialEq, Eq)]
97pub enum Count {
98    Fixed(u32),
99    Odo(Odo),
100}
101
102/// WHENEVER's classes: SQLCODE < 0, SQLCODE = 100, or a warning.
103#[derive(Clone, Copy, Debug, PartialEq, Eq)]
104pub enum SqlTest {
105    Error,
106    NotFound,
107    Warning,
108}
109
110codec_enum!(Operand { Load(place) = 0, Const(id) = 1, LengthOf(place) = 2, AddressOf(place) = 3, Function(id) = 4 });
111codec_enum!(Const { Bytes(b) = 0, National(n) = 1, Number(f) = 2, Figurative(f) = 3, All(b) = 4 });
112codec_enum!(IntExpr { Const(n) = 0, Item(place) = 1, Fixed { expr, dmax, prepass } = 2 });
113codec_enum!(Expr { Operand(o) = 0, Neg(e) = 1, Bin(a, op, b) = 2, Pow(base, exponent) = 3 });
114codec_enum!(Cond {
115    Rel { a, op, b, how } = 0,
116    Class { place, test } = 1,
117    Sign { value, test } = 2,
118    Name { subject, values, how } = 3,
119    Not(c) = 4,
120    And(a, b) = 5,
121    Or(a, b) = 6,
122    Counter(t) = 7,
123    InTable { index, count } = 8,
124    Sql(test) = 9,
125});
126codec_enum!(Comparand { Operand(o) = 0, Expr { expr, dmax, mode, prepass } = 1 });
127codec_enum!(Compare {
128    PackedPfd = 0,
129    Address = 1,
130    Float = 2,
131    Fixed = 3,
132    National = 4,
133    Alphanumeric = 5,
134    Refused(abend) = 6,
135    References = 7,
136});
137codec_enum!(ByteClass { Packed { signed } = 0, Zoned { signed } = 1, Digits = 2, Alphabetic = 3 });
138codec_enum!(SignTest { Positive = 0, Negative = 1, Zero = 2 });
139codec_enum!(Count { Fixed(n) = 0, Odo(odo) = 1 });
140codec_enum!(SqlTest { Error = 0, NotFound = 1, Warning = 2 });