Supporting FSM functions into C macros & cleanup smtp.cpp
[eventxx/ioevent.git] / hla-test / fsm.hhf
blobfbe7b69082ae3060af3e59460f520edbad045925
2 #if( ! @defined( fsm_hhf ))
3 ?fsm_hhf := true;
5 #includeonce( "hla.hhf" )
8 type
9         myfsm : record
10                 current_state : dword;
11         endrecord;
13 #macro fsm_callback ( _cbfunc_, _extname_ ) ;
15 procedure _cbfunc_
17         ev : dword;
18         old_state : dword;
19         ctx : dword
20 );      @cdecl;
21         @external( _extname_ );
23 #endmacro
25 #macro fsm_callback2 ( _cbfunc_, _extname_ ) ;
27 procedure _cbfunc_
29         ev : dword;
30         ctx : dword
31 );      @cdecl;
32         @external( _extname_ );
34 #endmacro
36 #macro fsm_advance ( _fsm_, _event_, _ctx_ ) :
37         _fsm_end_;
39         push ( eax );
40         push ( ebx );
41         push ( ecx );
42         push ( edx );
44         mov ( fsm, ebx );
45         mov ( (type myfsm [ebx]).current_state, eax );
47         mov ( _event_, ecx );
49         mov ( _ctx_, edx );
51 #keyword tr ( _state_, _ev_, _new_state_, _cbfunc_ ) :
52         _tr_end_;
54         cmp ( eax, _state_ );
55         jnz _tr_end_;
57         cmp ( ecx, _ev_ );
58         jnz _tr_end_;
60         mov ( _new_state_, eax );
62         mov ( eax, (type myfsm [ebx]).current_state );
64         push ( edx );
65         push ( eax );
66         push ( ecx );
67         call ( _cbfunc_ );
68         jmp _fsm_end_;
70 _tr_end_:
72 #keyword tr2 ( _state_, _ev_, _new_state_, _cbfunc_ ) :
73         _tr2_end_;
75         cmp ( eax, _state_ );
76         jnz _tr2_end_;
78         cmp ( ecx, _ev_ );
79         jnz _tr2_end_;
81         mov ( eax, (type myfsm [ebx]).current_state );
83         push ( edx ); // _ctx_
84         push ( ecx ); // _ev_
85         call ( _cbfunc_ ); // _cb_func_ ( _ev_, _ctx_ );
86         jmp _fsm_end_;
88 _tr2_end_:
90 #terminator end_fsm_advance;
92 _fsm_end_:
94         pop ( edx );
95         pop ( ecx );
96         pop ( ebx );
97         pop ( eax );
99 #endmacro
101 #endif