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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
use crate::{HashM, HashMt, IdentityEqual};
use crate::imp::structs::ref_value::RefSabValue;
use crate::imp::structs::list_value::{ListDefValue};
use crate::imp::structs::rust_param::RustParam;
use crate::imp::structs::util::set_sabun::{SetSabunError, verify_set_sabun};
use crate::imp::structs::list_def_obj::ListDefObj;
use crate::imp::structs::linked_m::LinkedMap;
use crate::imp::structs::util::hash_m::{HashS};
use crate::imp::structs::list_sab_value::ListSabValue;
use std::sync::Arc;
use once_cell::sync::Lazy;
#[derive(Debug, Clone, PartialEq)]
pub struct ConstTable {
default : Box<ListDefObj>,
list : Box<HashM<String, ConstItem>>,
old : Box<HashS<String>>,
}
impl ConstTable {
pub(crate) fn new(default : ListDefObj, list : HashM<String, ConstItem>, old : HashS<String>) -> ConstTable {
ConstTable { default : Box::new(default), list : Box::new(list), old : Box::new(old) }
}
pub(crate) fn default(&self) -> &ListDefObj{ self.default.as_ref() }
pub(crate) fn list(&self) -> &HashM<String, ConstItem>{ self.list.as_ref() }
pub(crate) fn old(&self) -> &HashS<String>{ self.old.as_ref() }
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConstList {
default : Box<ListDefObj>,
list : Box<Vec<ConstItem>>,
}
impl ConstList {
pub(crate) fn new(default : ListDefObj, list : Vec<ConstItem>) -> ConstList { ConstList { default : Box::new(default), list : Box::new(list) } }
pub(crate) fn default(&self) -> &ListDefObj{ self.default.as_ref() }
pub(crate) fn list(&self) -> &Vec<ConstItem>{ self.list.as_ref() }
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConstListVal {
list : Arc<Vec<ConstItem>>,
}
impl ConstListVal {
pub(crate) fn new(list : Vec<ConstItem>) -> ConstListVal { ConstListVal { list : Arc::new(list) }}
pub(crate) fn list(&self) -> &Vec<ConstItem>{ self.list.as_ref() }
pub(crate) fn empty() -> &'static Vec<ConstItem>{
static EMP_VEC: Vec<ConstItem> = Vec::new();
&EMP_VEC
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct MutListVal {
list : Arc<LinkedMap<MutItem>>,
}
impl MutListVal {
pub fn new(list : LinkedMap<MutItem>) -> MutListVal { MutListVal { list : Arc::new(list) } }
pub(crate) fn deconstruct(self) -> Arc<LinkedMap<MutItem>>{ self.list }
pub fn list(&self) -> &LinkedMap<MutItem>{ self.list.as_ref() }
pub fn list_mut(&mut self) -> &mut LinkedMap<MutItem>{ Arc::make_mut(&mut self.list) }
pub fn crate_empty_list() -> MutListVal{ MutListVal { list : Arc::new(LinkedMap::new())}}
pub fn empty_lists_ref() -> &'static LinkedMap<MutItem> {
static EMP: Lazy<LinkedMap<MutItem>> = Lazy::new(|| LinkedMap::new());
&EMP
}
}
impl IdentityEqual for MutListVal {
fn identity_eq(&self, other: &Self) -> bool {
self.list.identity_eq(&other.list)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConstItem {
values : Box<HashM<String, ListSabValue>>,
refs : Box<HashM<String, RefSabValue>>,
}
impl ConstItem {
pub(crate) fn new(values : HashM<String, ListSabValue>, refs : HashM<String, RefSabValue>) -> ConstItem {
ConstItem { values : Box::new(values), refs : Box::new(refs) }
}
pub(crate) fn values(&self) -> &HashM<String, ListSabValue>{ self.values.as_ref() }
pub(crate) fn refs(&self) -> &HashM<String, RefSabValue>{ self.refs.as_ref() }
}
#[derive(Debug, Clone, PartialEq)]
pub struct MutItem {
values : Arc<HashM<String, ListSabValue>>,
refs : Arc<HashM<String, RefSabValue>>,
}
impl MutItem {
pub fn new(values : HashM<String, ListSabValue>, refs : HashM<String, RefSabValue>) -> MutItem {
MutItem { values : Arc::new(values), refs : Arc::new(refs) }
}
pub(crate) fn default() -> MutItem {
MutItem { values : Arc::new(HashMt::new()), refs : Arc::new(HashMt::new()) }
}
pub fn muts(&mut self) -> (&mut HashM<String, ListSabValue>,
&mut HashM<String, RefSabValue>){
(Arc::make_mut(&mut self.values), Arc::make_mut(&mut self.refs))
}
pub fn construct(values : Arc<HashM<String, ListSabValue>>,
refs : Arc<HashM<String, RefSabValue>>) -> MutItem{
MutItem{ values, refs }
}
pub fn values(&self) -> &HashM<String, ListSabValue>{ self.values.as_ref() }
pub fn values_mut(&mut self) -> &mut HashM<String, ListSabValue>{ Arc::make_mut(&mut self.values) }
pub fn refs(&self) -> &HashM<String, RefSabValue>{ self.refs.as_ref() }
pub fn refs_mut(&mut self) -> &mut HashM<String, RefSabValue>{ Arc::make_mut(&mut self.refs) }
pub(crate) fn set_sabun(&mut self, def :&ListDefObj, name : String, param : RustParam) -> Result<Option<RustParam>, SetSabunError> {
let (p, vt) =
if let Some(ListDefValue::Param(p, vt)) = def.default().get(&name) {
(p, vt)
} else {
return Err(SetSabunError::ParamNotFound);
};
verify_set_sabun(p, vt, ¶m)?;
let op = self.values_mut().insert(name, ListSabValue::Param(param));
Ok(op.map(|v| match v{
ListSabValue::Param(p) => p,
_ => unreachable!(),
}))
}
}
impl IdentityEqual for MutItem{
fn identity_eq(&self, other: &Self) -> bool {
self.values.identity_eq(&other.values) &&
self.refs.identity_eq(&other.refs)
}
}