Skip to main content

ironwork_rt/
vocab.rs

1//! The vocabulary the front end, the interpreter and a compiled program share: source positions
2//! and the small enums of the data division, INSPECT and OPEN.
3
4use std::fmt;
5
6/// Where a diagnostic points: 1-based source line and column.
7#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
8pub struct Pos {
9    /// Index into the program's file table: 0 for the program itself, then each COPY member.
10    pub file: u16,
11    pub line: u32,
12    pub col: u32,
13}
14
15impl fmt::Display for Pos {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        write!(f, "{}:{}", self.line, self.col)
18    }
19}
20
21#[derive(Clone, Copy, Debug, PartialEq, Eq)]
22pub enum SignPosition {
23    Leading,
24    Trailing,
25}
26
27#[derive(Clone, Copy, Debug, PartialEq, Eq)]
28pub struct SignClause {
29    pub position: SignPosition,
30    pub separate: bool,
31}
32
33#[derive(Clone, Copy, Debug, PartialEq, Eq)]
34pub enum InspectMode {
35    Characters,
36    All,
37    Leading,
38    First,
39}
40
41#[derive(Clone, Copy, Debug, PartialEq, Eq)]
42pub enum Figurative {
43    Zero,
44    Space,
45    HighValue,
46    LowValue,
47    Quote,
48    Null,
49}
50
51#[derive(Clone, Copy, Debug, PartialEq, Eq)]
52pub enum BinOp {
53    Add,
54    Sub,
55    Mul,
56    Div,
57    Pow,
58}
59
60#[derive(Clone, Copy, Debug, PartialEq, Eq)]
61pub enum RelOp {
62    Eq,
63    Ne,
64    Lt,
65    Le,
66    Gt,
67    Ge,
68}
69
70#[derive(Clone, Copy, Debug, PartialEq, Eq)]
71pub enum OpenMode {
72    Input,
73    Output,
74    Extend,
75    InputOutput,
76}
77
78/// The phrases CLOSE can write after a file-name.
79#[derive(Clone, Copy, Debug, PartialEq, Eq)]
80pub enum Closing {
81    /// REEL or UNIT, with FOR REMOVAL, WITH NO REWIND or neither: the volume, not the file.
82    Volume,
83    NoRewind,
84    /// WITH LOCK: the file cannot be opened again while the program is in the run unit.
85    Lock,
86}
87
88#[derive(Clone, Copy, Debug, PartialEq, Eq)]
89pub enum AcceptFrom {
90    Sysin,
91    Date { four_digit_year: bool },
92    Day { four_digit_year: bool },
93    DayOfWeek,
94    Time,
95}