-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmachine.fs
56 lines (48 loc) · 1.12 KB
/
machine.fs
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
\ RilouwShell 0.1.0
\ Copyright (c) 2019 Jerome Martin
\ Released under the terms of the GNU GPL version 3
\ http://rilouw.eu/project/rilouwshell
struct
ptr% field machine-state
ptr% field machine-states
end-struct machine%
struct
ptr% field state-page
ptr% field state-transitions
end-struct state%
0 value current-machine
: current-page ( -- page )
current-machine machine-state @
state-page @
;
: go-page ( page -- )
drop
;
: state-machine ( -- #state ) 0 ;
: end-state-machine ( ...states #state <name> -- )
create machine% %allot >r
dup make-array
( ...states #state array )
dup r@ machine-states !
rev-read-array
\ set first state
0 r@ machine-states @ array@
r> machine-state !
;
: state ( -- #trans ) 0 ;
: end-state ( #state page ...trans #trans -- state #state )
state% %allot >r
dup make-array
dup r@ state-transitions !
rev-read-array
r@ state-page !
1+ \ increment #state
r> swap
;
: -> ( -- xt colon-sys ) :noname ;
: <- ( #trans event xt colon-sys -- trans #trans )
postpone ;
here -rot
swap , , \ put event and xt here
swap 1+ \ increment #trans
; immediate