Skip to content

Commit 72c132f

Browse files
committed
state and switch page
1 parent a1c781a commit 72c132f

1 file changed

Lines changed: 34 additions & 7 deletions

File tree

docs/doc-plan.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,15 @@ accounts for their long form.
3333

3434
A program consists of (at most) 5 pages, identified
3535
by `page_i:`, where 1 <= i <= 5.
36-
Each page identifier is followed by a (possibly empty)
37-
sequence of rules RULE:
36+
Each page identifier appears at most once and
37+
is followed by a (possibly empty) sequence of rules RULE:
3838

3939
```
4040
page_i: RULE*
4141
```
4242

4343
Rules that are presented without a preceding page identifier
4444
are added to page 1. Pages need not be presented in order.
45-
Each page identifier can appear at most once.
4645

4746
Each rule has an optional section WHEN and an optional section DO.
4847

@@ -152,8 +151,7 @@ Execution begins by transitioning (switching) to page 1.
152151
The absence of an optional element/value in the when or do section of a rule
153152
results in the use of a default element/value, as follows:
154153

155-
- A rule with an empty do section never executes (no matching performed
156-
on it).
154+
- A rule with an empty do section never executes (no matching performed on it).
157155
- A rule with an empty when section defaults to start_page signal with no delay.
158156
- Signal defaults are as follows
159157
- start_page defaults to no delay
@@ -187,7 +185,7 @@ Regardless of their origin, signals are ordered and processed one
187185
at a time using a FIFO queue. Each signal has a name corresponding to
188186
the signals named in the when section; a signal carries a payload, which
189187
may be an event or a value. Some special kinds of signals are
190-
used for timers, as detailed later.
188+
used for batch updates to variables and timers, as detailed later.
191189

192190
### Resources and conflicts
193191

@@ -205,7 +203,7 @@ Actions have effects by writing to (updating) a resource, which are as follows:
205203
If two rules have actions that update the same resource, they are said
206204
to be in _conflict_ if it is possible for them to execute at the same time.
207205

208-
### Rule matching
206+
### Rule matching and execution
209207

210208
Upon reception of a signal, it is first necessary to find the
211209
rules that are _enabled_ for execution by the signal. The first
@@ -237,10 +235,39 @@ T are started.
237235

238236
### Updating state
239237

238+
We guarantee that all actions that are executed `instantly` will read from
239+
the same state, even if they update variables; we do so by
240+
queuing updates to variables for processing later, rather than applying
241+
updates immediately to the current state. By construction,
242+
updates to variables (or any other resource) are guaranteed not to conflict,
243+
so the order in which the instant actions are executed does not matter.
244+
245+
The set of updated variables and their (potentially new) values are processed
246+
together as follows: TBD - updates to variables are batched together in
247+
an aggregate-signal.
248+
240249
### Switching pages
241250

251+
Rules from different pages should never execute simultaneously.
252+
When switching from the current page to another page N (even if the
253+
same), the following takes place
254+
255+
- pause generation and processing of signals
256+
- clear queue of all signals
257+
- halt all currently executing rules
258+
- set the current page to N
259+
- add start_page signal to queue
260+
- add aggregate signal for update of all variables to queue
261+
- start all timer-based rules
262+
- restore signal generation/processing
263+
242264
### Timers
243265

266+
When section sets a timer, when it fires, we generate a special
267+
timer_fired signal that specifies the rule's index and waits to
268+
receive that signal (this is done as all actions must execute
269+
in response to signals rather than invisible transitions).
270+
244271
## Example
245272

246273
Here is the MicroCode program corresponding to

0 commit comments

Comments
 (0)