Created
August 6, 2022 23:18
-
-
Save ityonemo/c6a54b54729bf09c993f72689d7ccdbe to your computer and use it in GitHub Desktop.
matching on attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule T do | |
@foo [%{foo: "bar"}] | |
def t(@foo) do | |
:ok | |
end | |
end | |
# DISASSEMBLED RESULT: | |
#{:function, :t, 1, 9, | |
# [ | |
# {:line, 1}, | |
# {:label, 8}, | |
# {:func_info, {:atom, T}, {:atom, :t}, 1}, | |
# {:label, 9}, | |
# {:test, :is_nonempty_list, {:f, 8}, [x: 0]}, | |
# {:get_list, {:x, 0}, {:x, 1}, {:x, 2}}, | |
# {:test, :is_map, {:f, 8}, [x: 1]}, | |
# {:get_map_elements, {:f, 8}, {:x, 1}, {:list, [atom: :foo, x: 1]}}, | |
# {:test, :is_eq_exact, {:f, 8}, [x: 1, literal: "bar"]}, | |
# {:test, :is_nil, {:f, 8}, [x: 2]}, | |
# {:move, {:atom, :ok}, {:x, 0}}, | |
# :return | |
# ]}, | |
# EXPECTED DISASSEMBLY: | |
# {:function, :t, 1, 9, | |
# [ | |
# {:line, 1}, | |
# {:label, 8}, | |
# {:func_info, {:atom, T}, {:atom, :t}, 1}, | |
# {:label, 9}, | |
# {:test, :is_eq_exact, {:f, 8}, [x: 0, literal: [%{foo: "bar"}]]}, | |
# {:move, {:atom, :ok}, {:x, 0}}, | |
# :return | |
# ]} | |
# COMPARE TO: `@foo ["bar"]` | |
# {:function, :t, 1, 9, | |
# [ | |
# {:line, 1}, | |
# {:label, 8}, | |
# {:func_info, {:atom, T}, {:atom, :t}, 1}, | |
# {:label, 9}, | |
# {:test, :is_eq_exact, {:f, 8}, [x: 0, literal: ["bar"]]}, | |
# {:move, {:atom, :ok}, {:x, 0}}, | |
# :return | |
# ]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment