Skip to content

Commit 90c8d7b

Browse files
committed
Forward port changes from v0.6 release branch
Merge a number of fixes for binary pattern matchin from release-0.6 branch. Also merge lists:keysort, FreeBSD CI workaround and Context struct members reorder.
2 parents b27a2a0 + 6425d02 commit 90c8d7b

File tree

16 files changed

+1084
-264
lines changed

16 files changed

+1084
-264
lines changed

.github/workflows/build-and-test-on-freebsd.yaml

Lines changed: 136 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -60,93 +60,139 @@ jobs:
6060
sync: rsync
6161
copyback: false
6262

63-
prepare: |
64-
pkg install -y curl cmake gperf erlang elixir rebar3 mbedtls3
65-
66-
run: |
67-
set -e
68-
echo "%%"
69-
echo "%% System Info"
70-
echo "%%"
71-
echo "**freebsd-version:**"
72-
freebsd-version
73-
echo "**uname:**"
74-
uname -a
75-
echo "**C Compiler version:**"
76-
clang --version
77-
clang++ --version
78-
echo "**CMake version:**"
79-
cmake --version
80-
echo "**hw.ncpu:**"
81-
sysctl -n hw.ncpu
82-
83-
sed -i '' 's/test_http_server/%test_http_server/g' tests/libs/eavmlib/tests.erl
84-
85-
echo "%%"
86-
echo "%% Running CMake ..."
87-
echo "%%"
88-
mkdir build
89-
cd build
90-
cmake .. -DMBEDTLS_ROOT_DIR=/usr/local -DAVM_WARNINGS_ARE_ERRORS=ON
91-
92-
echo "%%"
93-
echo "%% Building AtomVM ..."
94-
echo "%%"
95-
make -j `sysctl -n hw.ncpu`
96-
97-
echo "%%"
98-
echo "%% Running test-erlang ..."
99-
echo "%%"
100-
./tests/test-erlang
101-
102-
echo "%%"
103-
echo "%% Running test-enif ..."
104-
echo "%%"
105-
./tests/test-enif
106-
107-
echo "%%"
108-
echo "%% Running test-heap ..."
109-
echo "%%"
110-
./tests/test-heap
111-
112-
echo "%%"
113-
echo "%% Running test-mailbox ..."
114-
echo "%%"
115-
./tests/test-mailbox
116-
117-
echo "%%"
118-
echo "%% Running test-structs ..."
119-
echo "%%"
120-
./tests/test-structs
121-
122-
echo "%%"
123-
echo "%% Running etest tests ..."
124-
echo "%%"
125-
./src/AtomVM tests/libs/etest/test_etest.avm
126-
127-
echo "%%"
128-
echo "%% Running estdlib tests ..."
129-
echo "%%"
130-
./src/AtomVM tests/libs/estdlib/test_estdlib.avm
131-
132-
echo "%%"
133-
echo "%% Running eavmlib tests ..."
134-
echo "%%"
135-
./src/AtomVM tests/libs/eavmlib/test_eavmlib.avm
136-
137-
echo "%%"
138-
echo "%% Running alisp tests ..."
139-
echo "%%"
140-
./src/AtomVM tests/libs/alisp/test_alisp.avm
141-
142-
echo "%%"
143-
echo "%% Running install ..."
144-
echo "%%"
145-
make install
146-
atomvm examples/erlang/hello_world.avm
147-
atomvm -v
148-
atomvm -h
149-
150-
echo "%%"
151-
echo "%% Done!"
152-
echo "%%"
63+
- name: "Install deps"
64+
shell: freebsd {0}
65+
run: |
66+
pkg install -y curl cmake gperf erlang elixir rebar3 mbedtls3
67+
68+
- name: "System info"
69+
shell: freebsd {0}
70+
run: |
71+
set -e
72+
echo "%%"
73+
echo "%% System Info"
74+
echo "%%"
75+
echo "**freebsd-version:**"
76+
freebsd-version
77+
echo "**uname:**"
78+
uname -a
79+
echo "**C Compiler version:**"
80+
clang --version
81+
clang++ --version
82+
echo "**CMake version:**"
83+
cmake --version
84+
echo "**hw.ncpu:**"
85+
sysctl -n hw.ncpu
86+
87+
- name: Disable eavmlib's test_http_server
88+
shell: freebsd {0}
89+
run: |
90+
cd $GITHUB_WORKSPACE;
91+
sed -i '' 's/test_http_server/%test_http_server/g' tests/libs/eavmlib/tests.erl
92+
93+
- name: "Build: create build dir"
94+
shell: freebsd {0}
95+
run: |
96+
cd $GITHUB_WORKSPACE;
97+
mkdir build
98+
99+
- name: "Build: run cmake"
100+
shell: freebsd {0}
101+
run: |
102+
cd $GITHUB_WORKSPACE;
103+
cd build
104+
cmake .. -DMBEDTLS_ROOT_DIR=/usr/local -DAVM_WARNINGS_ARE_ERRORS=ON
105+
106+
- name: "Build: run make"
107+
shell: freebsd {0}
108+
run: |
109+
cd $GITHUB_WORKSPACE;
110+
cd build
111+
make -j `sysctl -n hw.ncpu`
112+
113+
- name: "Build: run dialyzer"
114+
shell: freebsd {0}
115+
run: |
116+
cd $GITHUB_WORKSPACE;
117+
cd build
118+
make -j `sysctl -n hw.ncpu`
119+
120+
- name: "Test: test-erlang"
121+
shell: freebsd {0}
122+
run: |
123+
cd $GITHUB_WORKSPACE;
124+
cd build
125+
./tests/test-erlang
126+
127+
- name: "Test: test-enif"
128+
shell: freebsd {0}
129+
run: |
130+
cd $GITHUB_WORKSPACE;
131+
cd build
132+
./tests/test-enif
133+
134+
- name: "Test: test-heap"
135+
shell: freebsd {0}
136+
run: |
137+
cd $GITHUB_WORKSPACE;
138+
cd build
139+
./tests/test-heap
140+
141+
- name: "Test: test-mailbox"
142+
shell: freebsd {0}
143+
run: |
144+
cd $GITHUB_WORKSPACE;
145+
cd build
146+
./tests/test-mailbox
147+
148+
- name: "Test: test-structs"
149+
shell: freebsd {0}
150+
run: |
151+
cd $GITHUB_WORKSPACE;
152+
cd build
153+
./tests/test-structs
154+
155+
- name: "Test: test_etest.avm"
156+
shell: freebsd {0}
157+
run: |
158+
cd $GITHUB_WORKSPACE;
159+
cd build
160+
./src/AtomVM tests/libs/etest/test_etest.avm
161+
162+
- name: "Test: test_estdlib.avm"
163+
shell: freebsd {0}
164+
run: |
165+
cd $GITHUB_WORKSPACE;
166+
cd build
167+
./src/AtomVM tests/libs/estdlib/test_estdlib.avm
168+
169+
- name: "Test: test_eavmlib.avm"
170+
shell: freebsd {0}
171+
run: |
172+
cd $GITHUB_WORKSPACE;
173+
cd build
174+
./src/AtomVM tests/libs/eavmlib/test_eavmlib.avm
175+
176+
- name: "Test: test_alisp.avm"
177+
shell: freebsd {0}
178+
run: |
179+
cd $GITHUB_WORKSPACE;
180+
cd build
181+
./src/AtomVM tests/libs/alisp/test_alisp.avm
182+
183+
- name: "Test: Tests.avm (Elixir)"
184+
shell: freebsd {0}
185+
run: |
186+
cd $GITHUB_WORKSPACE;
187+
cd build
188+
./src/AtomVM ./tests/libs/exavmlib/Tests.avm
189+
190+
- name: "Install and smoke test"
191+
shell: freebsd {0}
192+
run: |
193+
cd $GITHUB_WORKSPACE;
194+
cd build
195+
make install
196+
atomvm examples/erlang/hello_world.avm
197+
atomvm -v
198+
atomvm -h

.github/workflows/run-tests-with-beam.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@ jobs:
4343
- os: "ubuntu-24.04"
4444
test_erlang_opts: "-s prime_smp"
4545
container: erlang:21
46+
archive: "true"
4647

4748
- os: "ubuntu-24.04"
4849
test_erlang_opts: "-s prime_smp"
4950
container: erlang:22
51+
archive: "true"
5052

5153
- os: "ubuntu-24.04"
5254
test_erlang_opts: "-s prime_smp"
5355
container: erlang:23
56+
archive: "true"
5457

5558
- os: "ubuntu-24.04"
5659
test_erlang_opts: "-s prime_smp"
@@ -89,6 +92,11 @@ jobs:
8992
with:
9093
submodules: 'recursive'
9194

95+
- name: "Switch to archive.debian.org"
96+
if: matrix.archive == 'true'
97+
run: |
98+
sed -i 's|deb\.debian\.org|archive.debian.org/debian-archive|g' /etc/apt/sources.list
99+
92100
- name: "Install deps (container)"
93101
if: runner.os == 'Linux'
94102
run: |

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7070

7171
## [0.6.7] - Unreleased
7272

73+
### Added
74+
75+
- Added `lists:keysort/2`
76+
77+
### Fixed
78+
79+
- Fixed a bug where binary matching could fail due to a missing preservation of the matched binary.
80+
7381
## [0.6.6] - 2025-06-23
7482

7583
### Added

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ project(AtomVM)
2424
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
2525

2626
find_package(Dialyzer)
27+
find_package(Erlang)
2728
find_package(Elixir)
2829
find_package(Gleam)
2930

CMakeModules/FindErlang.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# This file is part of AtomVM.
3+
#
4+
# Copyright 2025 Paul Guyot <pguyot@kallisys.net>
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
#
20+
21+
find_program(ERLC_PATH erlc)
22+
find_program(ERL_PATH erl)
23+
24+
if (ERLC_PATH AND ERL_PATH)
25+
set(Erlang_FOUND TRUE)
26+
27+
execute_process(COMMAND ${ERL_PATH} -eval "io:put_chars(erlang:system_info(otp_release))" -s init stop -noshell
28+
OUTPUT_VARIABLE Erlang_VERSION)
29+
message("Found Erlang OTP ${Erlang_VERSION}")
30+
elseif(Erlang_FIND_REQUIRED)
31+
message(FATAL_ERROR "Erlang or Erlang compiler not found")
32+
endif()

libs/estdlib/src/lists.erl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
keyfind/3,
4545
keymember/3,
4646
keyreplace/4,
47+
keysort/2,
4748
keystore/4,
4849
keytake/3,
4950
foldl/3,
@@ -335,6 +336,17 @@ keyreplace(Key, N, [H | Tail], _OrigL, NewTuple, Acc) when element(N, H) =:= Key
335336
keyreplace(Key, N, [H | Tail], OrigL, NewTuple, Acc) ->
336337
keyreplace(Key, N, Tail, OrigL, NewTuple, [H | Acc]).
337338

339+
%%-----------------------------------------------------------------------------
340+
%% @param N the position in the tuple to compare (1..tuple_size)
341+
%% @param L the list to sort
342+
%% @returns The list L sorted by Nth element
343+
%% @doc Sort a list of tuples by Nth element.
344+
%% @end
345+
%%-----------------------------------------------------------------------------
346+
-spec keysort(N :: pos_integer(), L :: [tuple()]) -> [tuple()].
347+
keysort(N, TupleList) ->
348+
sort(fun(E1, E2) -> element(N, E1) < element(N, E2) end, TupleList).
349+
338350
%%-----------------------------------------------------------------------------
339351
%% @param Key the key to match
340352
%% @param N the position in the tuple to compare (1..tuple_size)

src/libAtomVM/context.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,35 @@ enum HeapGrowthStrategy
8383

8484
struct Context
8585
{
86+
// JIT compiler expects fields to be at given offset or sizes.
87+
// Do not change order or size without bumping the jit version
88+
8689
// First fields matches ErlNifEnv structure.
8790
GlobalContext *global;
8891
Heap heap;
8992
term *e;
93+
94+
// Following fields offsets are also hard-coded in jit backends
9095
term x[MAX_REG + 1];
91-
struct ListHead extended_x_regs;
96+
term cp;
97+
avm_float_t *fr;
98+
term bs;
99+
size_t bs_offset;
100+
// End of hard-coded section
92101

102+
struct ListHead extended_x_regs;
93103
struct ListHead processes_list_head;
94-
95104
struct ListHead processes_table_head;
96105
int32_t process_id;
97106

98107
struct TimerListItem timer_list_head;
99108

100109
struct ListHead monitors_head;
101110

102-
avm_float_t *fr;
103-
104111
size_t min_heap_size;
105112
size_t max_heap_size;
106113
enum HeapGrowthStrategy heap_growth_strategy;
107114

108-
term cp;
109-
110115
// saved state when scheduled out
111116
Module *saved_module;
112117
const void *saved_ip;
@@ -139,9 +144,6 @@ struct Context
139144

140145
term group_leader;
141146

142-
term bs;
143-
size_t bs_offset;
144-
145147
term exit_reason;
146148
};
147149

0 commit comments

Comments
 (0)