1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use crate::language::InternSymbol;
use crate::debug::DebugSymbol;
use crate::parser::expr::Expr;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Label(InternSymbol);
impl Label {
pub fn new(name: InternSymbol) -> Self { Label(name) }
pub fn name(&self) -> &InternSymbol { &self.0 }
}
#[derive(Debug, Clone)]
pub enum Stmt {
Expression(Expr),
Loop {
label: Option<Label>,
body: StmtList,
},
WhileLoop {
label: Option<Label>,
condition: Expr,
body: StmtList,
},
ForLoop { },
Assert(Expr),
}
#[derive(Debug, Clone)]
pub struct StmtList {
suite: Box<[StmtMeta]>,
control: Option<ControlFlow>,
}
#[derive(Debug, Clone)]
pub enum ControlFlow {
Continue(Option<Label>, Option<DebugSymbol>),
Break(Option<Label>, Option<Box<Expr>>, Option<DebugSymbol>),
Return(Option<Box<Expr>>, Option<DebugSymbol>),
}
impl StmtList {
pub fn new(suite: Vec<StmtMeta>, control: Option<ControlFlow>) -> Self {
Self {
suite: suite.into_boxed_slice(),
control,
}
}
pub fn iter(&self) -> impl Iterator<Item=&StmtMeta> {
self.suite.iter()
}
pub fn end_control(&self) -> Option<&ControlFlow> { self.control.as_ref() }
pub fn take(self) -> (Vec<StmtMeta>, Option<ControlFlow>) {
(self.suite.into_vec(), self.control)
}
}
#[derive(Debug, Clone)]
pub struct StmtMeta {
variant: Stmt,
symbol: DebugSymbol,
}
impl StmtMeta {
pub fn new(variant: Stmt, symbol: DebugSymbol) -> Self {
StmtMeta { variant, symbol }
}
pub fn variant(&self) -> &Stmt { &self.variant }
pub fn take_variant(self) -> Stmt { self.variant }
pub fn debug_symbol(&self) -> &DebugSymbol { &self.symbol }
pub fn take_symbol(self) -> DebugSymbol { self.symbol }
pub fn take(self) -> (Stmt, DebugSymbol) { (self.variant, self.symbol) }
}