Skip to content

Commit

Permalink
Used typed params for all calls
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalIcing committed Jan 6, 2024
1 parent a7549b0 commit 2e11c28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
53 changes: 22 additions & 31 deletions lib/orb/defw_dsl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ defmodule Orb.DefwDSL do
define_elixir_def(call, def_kind, result_type, param_types, env)
end

defp define_elixir_def(call, def_kind, result_type, param_types \\ nil, %Macro.Env{file: file}) do
defp define_elixir_def(
call,
def_kind,
result_type,
param_types \\ nil,

Check warning on line 91 in lib/orb/defw_dsl.ex

View workflow job for this annotation

GitHub Actions / Build and test (26.0.2, 1.15.2)

variable "param_types" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 91 in lib/orb/defw_dsl.ex

View workflow job for this annotation

GitHub Actions / Build and test (25.3.2, 1.15.2)

variable "param_types" is unused (if the variable is not meant to be used, prefix it with an underscore)
%Macro.Env{file: file} = env
) do
{name, func_args} = Macro.decompose_call(call)
{_, meta, _} = call
# arity = length(args)

def_args =
case func_args do
Expand All @@ -109,35 +114,21 @@ defmodule Orb.DefwDSL do

def_call = {name, meta, def_args}

case param_types do
nil ->
quote do
unquote(def_kind)(unquote(def_call)) do
Orb.Instruction.typed_call(
unquote(result_type || :unknown_effect),
case {@wasm_func_prefix, unquote(name)} do
{nil, name} -> name
{prefix, name} -> "#{prefix}.#{name}"
end,
unquote(def_args)
)
end
end

param_types ->
quote do
unquote(def_kind)(unquote(def_call)) do
Orb.Instruction.typed_call(
unquote(result_type || :unknown_effect),
unquote(param_types),
case {@wasm_func_prefix, unquote(name)} do
{nil, name} -> name
{prefix, name} -> "#{prefix}.#{name}"
end,
unquote(def_args)
)
end
end
params = Orb.Func.Type.params_from_call_args(func_args, env, meta[:line])
param_types = for %{type: type} <- params, do: type

quote do
unquote(def_kind)(unquote(def_call)) do
Orb.Instruction.typed_call(
unquote(result_type || :unknown_effect),
unquote(param_types),
case {@wasm_func_prefix, unquote(name)} do
{nil, name} -> name
{prefix, name} -> "#{prefix}.#{name}"
end,
unquote(def_args)
)
end
end
end
end
4 changes: 2 additions & 2 deletions test/defw_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ defmodule DefwTest do

assert Visibilities.first() == %Orb.Instruction{
type: :unknown_effect,
operation: {:call, :first},
operation: {:call, [], :first},
operands: []
}

assert Visibilities.second() == %Orb.Instruction{
type: :unknown_effect,
operation: {:call, :second},
operation: {:call, [], :second},
operands: []
}

Expand Down

0 comments on commit 2e11c28

Please sign in to comment.