...
 
Commits (4)
......@@ -32,3 +32,6 @@ mix.lock
#Elixir_LS files
.elixir_ls
# Sublime Text
*.sublime-workspace
# A simple ping-pong example where two actors are continuously sending back-and-forth a message
#
# To run this example: iex -S mix run -r lib/examples/contracts/pingpong_contracts2.exs
use Marlon
defactor PingPongContracts2 do
def init([msg]) do
{:ok, %{msg: msg, return_actor: 0}}
end
async def set_return_actor(this, return_actor) do
{:noreply, %{this | return_actor: return_actor}}
end
async def ping(this) do
IO.puts this.msg
PingPongContracts2.ping(this.return_actor)
{:noreply, this}
end
defcontract do
[:set_return_actor, cycle :ping]
end
end
# Instantiate two PingPong actors
{:ok, ping} = PingPongContracts2.start_link(["Ping!"], [])
{:ok, pong} = PingPongContracts2.start_link(["Pong!"], [])
# Connect them to each other
PingPongContracts2.set_return_actor(ping, pong)
PingPongContracts2.set_return_actor(pong, ping)
# Start ping-ponging
# PingPongContracts2.ping(ping)
\ No newline at end of file
......@@ -47,6 +47,9 @@ defmodule Marlon do
client_fns = Enum.map(categorized.handlers, fn(handler) -> genclient_fn(handler) end)
server_fns = Enum.map(categorized.handlers, fn(handler) -> genserver_fn(handler) end)
# Compile contract
compiled_contract = compile_contract(categorized.contract)
quote do
defmodule unquote(name) do
use GenServer
......@@ -197,7 +200,7 @@ defmodule Marlon do
# Determine which of the members are GenServer handlers, and which are plain functions
defp categorize_members(members) do
Enum.reduce(members, %{handlers: [], fns: [], init: nil},
Enum.reduce(members, %{handlers: [], fns: [], init: nil, contract: nil},
fn(member, categorized) ->
cond do
(macro_name(member) == :async) or (macro_name(member) == :sync)or (macro_name(member) == :reply) ->
......@@ -206,12 +209,25 @@ defmodule Marlon do
%{categorized | init: member}
(macro_name(member) == :def) ->
%{categorized | fns: categorized.fns ++ [member]}
(macro_name(member) == :defcontract) ->
%{categorized | contract: member }
true ->
categorized # Ignore anything else..
end
end)
end
# Compile defcontract body
defp compile_contract(contract) do
case contract do
{_, _, b} ->
body = Enum.at(b, 0)[:do]
IO.puts Kernel.inspect(body)
# TODO: Call actual contract compiler
nil -> :no_contract
end
end
################################
## defgoal
......
{
"folders":
[
{
"path": ".",
"folder_exclude_patterns": [".idea", ".vscode", "_build", "deps"],
"file_exclude_patterns": ["mix.exs.lock", "*.iml"]
}
]
}
......@@ -41,8 +41,8 @@ defmodule Marlon.Mixfile do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:erlport, git: "https://github.com/hdima/erlport.git"},
{:libcluster, git: "https://gitlab.soft.vub.ac.be/tmoldere/libcluster.git"},
{:erlport, "~> 0.10.0"},
{:libcluster, "~> 3.0.2"},
{:smile_it_demo_ui, git: "https://github.com/rhumbertgz/smile_it_demo_ui.git"},
# {:exprof, "~> 0.2.0"},
{:csv, "~> 2.0.0"},
......