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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
mod canon_stream;
mod lambda_result;
mod resolved_call;
mod vec_resolved_call;
pub(crate) use canon_stream::CanonStreamIterableIngredients;
pub(crate) use lambda_result::IterableLambdaResult;
pub(crate) use resolved_call::IterableResolvedCall;
pub(crate) use vec_resolved_call::IterableVecResolvedCall;
use super::ValueAggregate;
use crate::execution_step::RcSecurityTetraplet;
use crate::JValue;
use air_interpreter_data::TracePos;
use std::rc::Rc;
pub(crate) trait Iterable<'ctx> {
type Item;
fn next(&mut self) -> bool;
fn prev(&mut self) -> bool;
fn peek(&'ctx self) -> Option<Self::Item>;
fn len(&self) -> usize;
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) enum IterableItem<'ctx> {
RefRef((&'ctx JValue, &'ctx RcSecurityTetraplet, TracePos)),
RefValue((&'ctx JValue, RcSecurityTetraplet, TracePos)),
RcValue((Rc<JValue>, RcSecurityTetraplet, TracePos)),
}
impl IterableItem<'_> {
pub(crate) fn pos(&self) -> TracePos {
use IterableItem::*;
let pos = match self {
RefRef((.., pos)) => pos,
RefValue((.., pos)) => pos,
RcValue((.., pos)) => pos,
};
*pos
}
pub(crate) fn into_resolved_result(self) -> ValueAggregate {
use IterableItem::*;
let (value, tetraplet, pos) = match self {
RefRef((value, tetraplet, pos)) => (Rc::new(value.clone()), tetraplet.clone(), pos),
RefValue((value, tetraplet, pos)) => (Rc::new(value.clone()), tetraplet, pos),
RcValue(ingredients) => ingredients,
};
ValueAggregate::new(value, tetraplet, pos)
}
}
#[macro_export]
macro_rules! foldable_next {
($self: expr, $len:expr) => {{
if $self.cursor + 1 < $len {
$self.cursor += 1;
true
} else {
false
}
}};
}
#[macro_export]
macro_rules! foldable_prev {
($self: expr) => {{
if $self.cursor >= 1 {
$self.cursor -= 1;
true
} else {
false
}
}};
}