Skip to content
Permalink
Browse files
Simplify clearing the stack
Killing the process made for some dirty log output since the exit wasn't
handled cleanly. Rather than trying to fix that we just add a message to
reset the stack state inside the same pid.
  • Loading branch information
davisp committed Feb 22, 2019
1 parent 709cb6f commit 0bd1c563ff758b53803bd225a32a2133f67cc781
Showing 1 changed file with 14 additions and 2 deletions.
@@ -48,6 +48,10 @@ stack_handle({From, log}, St) ->
From ! {self(), ok},
St;

stack_handle({From, clear}, _St) ->
From ! {self(), ok},
[];

stack_handle({From, length}, St) ->
From ! {self(), length(St)},
St;
@@ -83,6 +87,14 @@ stack_handle({From, pop, Count}, St) ->
%% receive {Pid, ok} -> ok end.


stack_clear(#st{stack = Pid}) ->
stack_clear(Pid);

stack_clear(Pid) ->
Pid ! {self(), clear},
receive {Pid, ok} -> ok end.


stack_size(#st{stack = Pid}) ->
stack_size(Pid);

@@ -323,8 +335,8 @@ execute(_TxObj, St, <<"DUP">>) ->
St;

execute(_TxObj, St, <<"EMPTY_STACK">>) ->
exit(St#st.stack, kill),
St#st{stack = stack_create()};
stack_clear(St),
St;

execute(_TxObj, St, <<"SWAP">>) ->
Idx = stack_pop(St),

0 comments on commit 0bd1c56

Please sign in to comment.