Skip to content

Commit

Permalink
Support GenServer.ex & Supervisor.ex
Browse files Browse the repository at this point in the history
Carbon copy from upstream, and adapted to gen_server.erl

Signed-off-by: Peter M <[email protected]>
  • Loading branch information
petermm committed Jan 15, 2025
1 parent 13b327d commit 531bdab
Show file tree
Hide file tree
Showing 11 changed files with 2,278 additions and 5 deletions.
8 changes: 4 additions & 4 deletions libs/estdlib/src/gen_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ call(Name, Request, TimeoutMs) when is_atom(Name) ->
end;
call(Pid, Request, TimeoutMs) when is_pid(Pid) ->
MonitorRef = monitor(process, Pid),
Pid ! {'$call', {self(), MonitorRef}, Request},
Pid ! {'$gen_call', {self(), MonitorRef}, Request},
receive
{'DOWN', MonitorRef, process, Pid, {E, []} = _Reason} ->
erlang:exit({E, {?MODULE, ?FUNCTION_NAME, [Pid, Request]}});
Expand Down Expand Up @@ -475,7 +475,7 @@ cast(Name, Request) when is_atom(Name) ->
cast(Pid, Request)
end;
cast(Pid, Request) when is_pid(Pid) ->
Pid ! {'$cast', Request},
Pid ! {'$gen_cast', Request},
ok.

%%-----------------------------------------------------------------------------
Expand Down Expand Up @@ -510,7 +510,7 @@ loop(Parent, #state{mod = Mod, mod_state = ModState} = State, {continue, Continu
end;
loop(Parent, #state{mod = Mod, mod_state = ModState} = State, Timeout) ->
receive
{'$call', {_Pid, _Ref} = From, Request} ->
{'$gen_call', {_Pid, _Ref} = From, Request} ->
case Mod:handle_call(Request, From, ModState) of
{reply, Reply, NewModState} ->
ok = reply(From, Reply),
Expand All @@ -535,7 +535,7 @@ loop(Parent, #state{mod = Mod, mod_state = ModState} = State, Timeout) ->
_ ->
do_terminate(State, {error, unexpected_reply}, ModState)
end;
{'$cast', Request} ->
{'$gen_cast', Request} ->
case Mod:handle_cast(Request, ModState) of
{noreply, NewModState} ->
loop(Parent, State#state{mod_state = NewModState}, infinity);
Expand Down
8 changes: 8 additions & 0 deletions libs/exavmlib/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ set(ELIXIR_MODULES
Enumerable.MapSet
Enumerable.Range
Exception
GenServer
GenServerTest.Stack
GenServerTest.CustomStack
SupervisorTest.Stack
SupervisorTest.Stack.Sup
IO
List
Map
MapSet
Module
Keyword
Supervisor
Supervisor.Default
Supervisor.Spec
Kernel
Process
Protocol.UndefinedError
Expand Down
Loading

0 comments on commit 531bdab

Please sign in to comment.