@@ -24,21 +24,19 @@ impl CsModelBuilder {
24
24
}
25
25
}
26
26
27
- pub fn add_port ( & mut self , channel : Channel , default : Val ) -> Result < ( ) , ( ) > {
27
+ pub fn add_port ( & mut self , channel : Channel , default : Val ) {
28
28
if let std:: collections:: hash_map:: Entry :: Vacant ( e) = self . vals . entry ( channel) {
29
29
e. insert ( default) ;
30
- Ok ( ( ) )
31
30
} else {
32
- Err ( ( ) )
31
+ panic ! ( "entry is already taken" ) ;
33
32
}
34
33
}
35
34
36
- pub fn add_predicate ( & mut self , predicate : Expression < Channel > ) -> Result < usize , ( ) > {
35
+ pub fn add_predicate ( & mut self , predicate : Expression < Channel > ) -> usize {
37
36
let predicate = FnExpression :: < Channel > :: from ( predicate) ;
38
37
let _ = predicate. eval ( & |port| self . vals . get ( & port) . unwrap ( ) . clone ( ) ) ;
39
- // let _ = predicate.eval(&|port| self.vals.get(&port).cloned());
40
38
self . predicates . push ( predicate) ;
41
- Ok ( self . predicates . len ( ) - 1 )
39
+ self . predicates . len ( ) - 1
42
40
}
43
41
44
42
/// Creates a new [`CsModel`] with the given underlying [`ChannelSystem`] and set of predicates.
@@ -69,6 +67,7 @@ pub struct CsModel {
69
67
70
68
impl CsModel {
71
69
/// Gets the underlying [`ChannelSystem`].
70
+ #[ inline( always) ]
72
71
pub fn channel_system ( & self ) -> & ChannelSystem {
73
72
& self . cs
74
73
}
@@ -81,10 +80,7 @@ impl TransitionSystem for CsModel {
81
80
self . predicates
82
81
. iter ( )
83
82
. map ( |prop| {
84
- if let Val :: Boolean ( b) = prop. eval ( & |port| self . vals . get ( & port) . unwrap ( ) . clone ( ) )
85
- // .eval(&|port| self.vals.get(&port).cloned())
86
- // .expect("boolean value")
87
- {
83
+ if let Val :: Boolean ( b) = prop. eval ( & |port| self . vals . get ( & port) . unwrap ( ) . clone ( ) ) {
88
84
Some ( b)
89
85
} else {
90
86
None
@@ -95,36 +91,22 @@ impl TransitionSystem for CsModel {
95
91
. unwrap ( )
96
92
}
97
93
98
- fn transitions ( mut self ) -> Vec < ( Event , CsModel ) > {
99
- // IntoIterator::into_iter(self.clone().list_transitions())
100
- // Perform all transitions that are deterministic and do not interact with channels.
101
- // The order in which these are performed does not matter.
102
- self . cs . resolve_deterministic_transitions ( ) ;
103
- if self . cs . possible_transitions ( ) . next ( ) . is_none ( ) {
104
- self . cs . wait ( 1 ) . ok ( ) ;
105
- }
106
- self . cs
107
- . possible_transitions ( )
108
- . flat_map ( |( pg_id, action, post) | {
109
- let mut model = self . clone ( ) ;
110
- let event = model
111
- . cs
112
- . transition ( pg_id, action, post)
113
- . expect ( "transition is possible" ) ;
114
- model. last_event = event. clone ( ) ;
115
- if let Some ( event) = event {
116
- if let EventType :: Send ( ref val) = event. event_type {
117
- model. vals . insert ( event. channel , val. to_owned ( ) ) ;
118
- }
119
- vec ! [ ( event, model) ]
120
- } else {
121
- model. transitions ( )
122
- }
123
- } )
124
- . collect :: < Vec < _ > > ( )
125
- }
126
-
94
+ #[ inline( always) ]
127
95
fn time ( & self ) -> Time {
128
96
self . cs . time ( )
129
97
}
98
+
99
+ fn monaco_transition < R : rand:: Rng > (
100
+ & mut self ,
101
+ rng : & mut R ,
102
+ duration : Time ,
103
+ ) -> Option < Self :: Action > {
104
+ self . last_event = self . cs . monaco_execution ( rng, duration) ;
105
+ if let Some ( event) = self . last_event . as_ref ( ) {
106
+ if let EventType :: Send ( ref val) = event. event_type {
107
+ self . vals . insert ( event. channel , val. to_owned ( ) ) ;
108
+ }
109
+ }
110
+ self . last_event . to_owned ( )
111
+ }
130
112
}
0 commit comments