Skip to content

Conversation

@mat-hek
Copy link
Contributor

@mat-hek mat-hek commented Nov 13, 2025

This builds on top of #1988

In some cases, there's generic code that uses the bitstring modifier because it needs to work for both bitstrings and binaries, for example in erl_eval. Currently such code doesn't work even if no actual bitstrings are involved, and this PR attempts to fix it. In other words, this now works:

defmodule Foo do
  def pattern_match(x, s) do
    case x do
      <<a::bitstring-size(s), b::bitstring>> ->
        {a, b}

      _ ->
        :no_match
    end
  end

  def create(y, s) do
    <<y::bitstring-size(s), 123>>
  end
end

Foo.pattern_match(<<234, 123, 2>>, 16)
# => {<<234, 123>>, <<2>>}
Foo.create(<<234, 123, 2>>, 16)
# => <<234, 123, 123>>

TODO:

  • add tests
  • adjust jit.erl

@mat-hek mat-hek force-pushed the mf/upstream-support-aligned-bitstrings branch 2 times, most recently from bb34fe8 to 7bb58f2 Compare November 13, 2025 14:37
@mat-hek mat-hek force-pushed the mf/upstream-support-aligned-bitstrings branch from 576fb54 to ffcc68d Compare November 18, 2025 11:21
mat-hek added a commit to software-mansion/popcorn that referenced this pull request Nov 18, 2025
…408)

Closes #393

Once atomvm/AtomVM#1978 is merged and
downstreamed, the eval_bits patch won't be needed (unless there are
other unrelated patches in there OFC)
@mat-hek mat-hek force-pushed the mf/upstream-support-aligned-bitstrings branch from ffcc68d to 89e5cf8 Compare November 19, 2025 09:42
@mat-hek mat-hek changed the title Support creating and matching bitstrings that are in fact binaries (size divisible by 8) Support matching bitstrings that are in fact binaries (size divisible by 8) Nov 19, 2025
@mat-hek mat-hek force-pushed the mf/upstream-support-aligned-bitstrings branch from 89e5cf8 to 7ef143a Compare November 19, 2025 14:42
@mat-hek mat-hek force-pushed the mf/upstream-support-aligned-bitstrings branch from 7ef143a to 5aa8f8c Compare November 19, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants