Skip to content

Commit

Permalink
Fix codegen to expand ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
sabiwara authored and michalmuskala committed Jun 29, 2024
1 parent 44fc70a commit 28ff2c2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/codegen.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Jason.Codegen do
end

defmacro bytecase(var, do: clauses) do
{ranges, default, literals} = clauses_to_ranges(clauses, [])
{ranges, default, literals} = clauses_to_ranges(clauses, [], __CALLER__)

jump_table = jump_table(ranges, default)

Expand All @@ -31,7 +31,7 @@ defmodule Jason.Codegen do
end

defmacro bytecase(var, max, do: clauses) do
{ranges, default, empty} = clauses_to_ranges(clauses, [])
{ranges, default, empty} = clauses_to_ranges(clauses, [], __CALLER__)

jump_table = jump_table(ranges, default, max)

Expand All @@ -51,11 +51,12 @@ defmodule Jason.Codegen do
collapse_static(List.flatten(["{", elements] ++ '}'))
end

defp clauses_to_ranges([{:->, _, [[{:in, _, [byte, range]}, rest], action]} | tail], acc) do
clauses_to_ranges(tail, [{range, {byte, rest, action}} | acc])
defp clauses_to_ranges([{:->, _, [[{:in, _, [byte, range]}, rest], action]} | tail], acc, env) do
range = Macro.expand(range, env)
clauses_to_ranges(tail, [{range, {byte, rest, action}} | acc], env)
end

defp clauses_to_ranges([{:->, _, [[default, rest], action]} | tail], acc) do
defp clauses_to_ranges([{:->, _, [[default, rest], action]} | tail], acc, _env) do
{Enum.reverse(acc), {default, rest, action}, literal_clauses(tail)}
end

Expand Down

0 comments on commit 28ff2c2

Please sign in to comment.