Skip to content

Commit 1bedd1c

Browse files
committed
Forward port changes from v0.6 release branch
Merge into main a number of changes, such as fixes and libraries improvements, aimed to enabling Erlang and Elixir REPL on a browser.
2 parents 22c0da4 + 7d63dc0 commit 1bedd1c

37 files changed

+14506
-87
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,31 @@ also non string parameters (e.g. `Enum.join([1, 2], ",")`
3030
- Add support for `handle_continue` callback in `gen_server`
3131
- Support for Elixir `List.Chars` protocol
3232
- Support for `gen_server:start_monitor/3,4`
33+
- Support for `code:ensure_loaded/1`
34+
- Support for `io_lib:latin1_char_list/1`
35+
- Add support to Elixir for `Keyword.split/2`
36+
- Support for `binary:split/3` and `string:find/2,3`
37+
- Support for large tuples (more than 255 elements) in external terms.
38+
- Support for `io:put_chars/2`
39+
- Support for `lists:nthtail/2`
40+
- Support for Elixir `IO.chardata_to_string/1`
41+
- Support for Elixir `List.duplicate/2`
42+
- Support for `binary:copy/1,2`
3343

3444
### Changed
3545

3646
- ESP32: Elixir library is not shipped anymore with `esp32boot.avm`. Use `elixir_esp32boot.avm`
3747
instead
3848
- `Enum.find_index` and `Enum.find_value` support Enumerable and not just lists
49+
- Install AtomVM libraries source code and binaries for better dialyzer integration
50+
- Made the `device_config` properties list in `spi:open/1` optional (defaults to `[]`), so you can use the function with only a `bus_config`
3951

4052
### Fixed
4153

4254
- ESP32: content of `boot.avm` partition is not truncated anymore
4355
- ESP32: `Fixed gpio:set_int` to accept any pin, not only pin 2
4456
- Fix memory corruption in `unicode:characters_to_binary`
45-
- Fix handling of large literal indexes
57+
- Fix handling of large literal indexes and large extended literal indexes
4658
- `unicode:characters_to_list`: fixed bogus out_of_memory error on some platforms such as ESP32
4759
- Fix crash in Elixir library when doing `inspect(:atom)`
4860
- General inspect() compliance with Elixir behavior (but there are still some minor differences)

doc/src/programmers-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,10 +1531,10 @@ The [`spi` module](./apidocs/erlang/eavmlib/spi.md) encapsulates functionality a
15311531
Information about the ESP32 SPI leader mode interface can be found in the IDF SDK [SPI Documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html).
15321532
```
15331533
1534-
The AtomVM SPI implementation uses the AtomVM Port mechanism and must be initialized using the [`spi:open/1`](./apidocs/erlang/eavmlib/spi.md#open1) function. The single parameter to this function is a properties list containing two elements:
1534+
The AtomVM SPI implementation uses the AtomVM Port mechanism and must be initialized using the [`spi:open/1`](./apidocs/erlang/eavmlib/spi.md#open1) function. The single parameter to this function is a properties list containing:
15351535
15361536
* [`bus_config`](./apidocs/erlang/eavmlib/spi.md#bus_config) -- a properties list containing entries for the SPI bus
1537-
* [`device_config`](./apidocs/erlang/eavmlib/spi.md#device_config) -- a properties list containing entries for each device attached to the SPI Bus
1537+
* [`device_config`](./apidocs/erlang/eavmlib/spi.md#device_config) -- an optional properties list containing entries for each device attached to the SPI Bus
15381538
15391539
The `bus_config` properties list contains the following entries:
15401540

libs/alisp/src/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,24 @@ set(ERLANG_MODULES
3232
)
3333

3434
pack_archive(alisp ${ERLANG_MODULES})
35+
36+
include(../../../version.cmake)
37+
38+
set(ALISP_VERSION ${ATOMVM_BASE_VERSION})
39+
40+
install(
41+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/beams/
42+
DESTINATION lib/atomvm/lib/alisp-${ALISP_VERSION}/ebin
43+
FILES_MATCHING PATTERN "*.beam"
44+
)
45+
46+
install(
47+
FILES ${CMAKE_CURRENT_BINARY_DIR}/alisp.avm
48+
DESTINATION lib/atomvm/lib/alisp-${ALISP_VERSION}/ebin/
49+
)
50+
51+
install(
52+
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
53+
DESTINATION lib/atomvm/lib/alisp-${ALISP_VERSION}/src
54+
FILES_MATCHING PATTERN "*.erl"
55+
)

libs/eavmlib/src/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,24 @@ set(ERLANG_MODULES
4646
)
4747

4848
pack_archive(eavmlib ${ERLANG_MODULES})
49+
50+
include(../../../version.cmake)
51+
52+
set(EAVMLIB_VERSION ${ATOMVM_BASE_VERSION})
53+
54+
install(
55+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/beams/
56+
DESTINATION lib/atomvm/lib/eavmlib-${EAVMLIB_VERSION}/ebin
57+
FILES_MATCHING PATTERN "*.beam"
58+
)
59+
60+
install(
61+
FILES ${CMAKE_CURRENT_BINARY_DIR}/eavmlib.avm
62+
DESTINATION lib/atomvm/lib/eavmlib-${EAVMLIB_VERSION}/ebin/
63+
)
64+
65+
install(
66+
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
67+
DESTINATION lib/atomvm/lib/eavmlib-${EAVMLIB_VERSION}/src
68+
FILES_MATCHING PATTERN "*.erl"
69+
)

libs/eavmlib/src/spi.erl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@
5959
| {command_len_bits, 0..16}
6060
].
6161
-type device_name() :: atom().
62-
-type params() :: [
63-
{bus_config, bus_config()}
64-
| {device_config, [{device_name(), device_config()}]}
65-
].
62+
-type params() ::
63+
[
64+
{bus_config, bus_config()}
65+
]
66+
| [
67+
{bus_config, bus_config()}
68+
| {device_config, [{device_name(), device_config()}]}
69+
].
6670

6771
-type spi() :: pid().
6872
-type address() :: non_neg_integer().
@@ -294,7 +298,7 @@ write_read(SPI, DeviceName, Transaction) when
294298
validate_params(Params) when is_map(Params) orelse is_list(Params) ->
295299
#{
296300
bus_config => validate_bus_config(get_value(bus_config, Params, undefined)),
297-
device_config => validate_device_config(get_value(device_config, Params, undefined))
301+
device_config => validate_device_config(get_value(device_config, Params, []))
298302
};
299303
validate_params(Params) ->
300304
throw({error, {not_a_map_or_list, Params}}).

libs/esp32devmode/src/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,24 @@ project(esp32devmode)
2323
include(BuildErlang)
2424

2525
pack_archive(esp32devmode esp32devmode)
26+
27+
include(../../../version.cmake)
28+
29+
set(ESP32DEVMODE_VERSION ${ATOMVM_BASE_VERSION})
30+
31+
install(
32+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/beams/
33+
DESTINATION lib/atomvm/lib/esp32devmode-${ESP32DEVMODE_VERSION}/ebin
34+
FILES_MATCHING PATTERN "*.beam"
35+
)
36+
37+
install(
38+
FILES ${CMAKE_CURRENT_BINARY_DIR}/esp32devmode.avm
39+
DESTINATION lib/atomvm/lib/esp32devmode-${ESP32DEVMODE_VERSION}/ebin/
40+
)
41+
42+
install(
43+
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
44+
DESTINATION lib/atomvm/lib/esp32devmode-${ESP32DEVMODE_VERSION}/src
45+
FILES_MATCHING PATTERN "*.erl"
46+
)

libs/estdlib/src/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,24 @@ set(ERLANG_MODULES
6161
)
6262

6363
pack_archive(estdlib ${ERLANG_MODULES})
64+
65+
include(../../../version.cmake)
66+
67+
set(ESTDLIB_VERSION ${ATOMVM_BASE_VERSION})
68+
69+
install(
70+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/beams/
71+
DESTINATION lib/atomvm/lib/estdlib-${ESTDLIB_VERSION}/ebin
72+
FILES_MATCHING PATTERN "*.beam"
73+
)
74+
75+
install(
76+
FILES ${CMAKE_CURRENT_BINARY_DIR}/estdlib.avm
77+
DESTINATION lib/atomvm/lib/estdlib-${ESTDLIB_VERSION}/ebin/
78+
)
79+
80+
install(
81+
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
82+
DESTINATION lib/atomvm/lib/estdlib-${ESTDLIB_VERSION}/src
83+
FILES_MATCHING PATTERN "*.erl"
84+
)

libs/estdlib/src/binary.erl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
%%-----------------------------------------------------------------------------
2525
-module(binary).
2626

27-
-export([at/2, part/3, split/2]).
27+
-export([at/2, part/3, split/2, split/3]).
2828

2929
%%-----------------------------------------------------------------------------
3030
%% @param Binary binary to get a byte from
@@ -51,6 +51,7 @@ part(_Binary, _Pos, _Len) ->
5151
erlang:nif_error(undefined).
5252

5353
%%-----------------------------------------------------------------------------
54+
%% @equiv split(Binary, Pattern, [])
5455
%% @param Binary binary to split
5556
%% @param Pattern pattern to perform the split
5657
%% @return a list composed of one or two binaries
@@ -62,3 +63,18 @@ part(_Binary, _Pos, _Len) ->
6263
-spec split(Binary :: binary(), Pattern :: binary()) -> [binary()].
6364
split(_Binary, _Pattern) ->
6465
erlang:nif_error(undefined).
66+
67+
%%-----------------------------------------------------------------------------
68+
%% @param Binary binary to split
69+
%% @param Pattern pattern to perform the split
70+
%% @param Options options for the split
71+
%% @return a list composed of one or two binaries
72+
%% @doc Split a binary according to pattern.
73+
%% If pattern is not found, returns a singleton list with the passed binary.
74+
%% Unlike Erlang/OTP, pattern must be a binary.
75+
%% Only implemented option is `global'
76+
%% @end
77+
%%-----------------------------------------------------------------------------
78+
-spec split(Binary :: binary(), Pattern :: binary(), Option :: [global]) -> [binary()].
79+
split(_Binary, _Pattern, _Option) ->
80+
erlang:nif_error(undefined).

libs/estdlib/src/code.erl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
all_available/0,
2929
all_loaded/0,
3030
load_abs/1,
31-
load_binary/3
31+
load_binary/3,
32+
ensure_loaded/1
3233
]).
3334

3435
%%-----------------------------------------------------------------------------
@@ -82,3 +83,18 @@ load_abs(_Filename) ->
8283
error | {module, module()}.
8384
load_binary(_Module, _Filename, _Binary) ->
8485
erlang:nif_error(undefined).
86+
87+
%%-----------------------------------------------------------------------------
88+
%% @param Module module to load
89+
%% @returns Tuple `{module, Module}' if module is loaded or `{error, embedded}'
90+
%% @doc Try to load a module if it's not already loaded. AtomVM works in
91+
%% an embedded-like mode where modules are loaded at start-up but modules
92+
%% can be loaded explicitely as well (especially from a binary with `load_binary/3').
93+
%% So this function can be used to determine if a module is loaded.
94+
%% It is called by Elixir Code module.
95+
%% @end
96+
%%-----------------------------------------------------------------------------
97+
-spec ensure_loaded(Module) -> {module, Module} | {error, embedded | any()} when
98+
Module :: atom().
99+
ensure_loaded(_Module) ->
100+
erlang:nif_error(undefined).

libs/estdlib/src/io.erl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
%%-----------------------------------------------------------------------------
2828
-module(io).
2929

30-
-export([format/1, format/2, get_line/1, put_chars/1]).
30+
-export([format/1, format/2, get_line/1, put_chars/1, put_chars/2]).
3131

3232
%%-----------------------------------------------------------------------------
3333
%% @doc Equivalent to format(Format, []).
@@ -96,3 +96,15 @@ put_chars(Chars) ->
9696
{io_reply, Ref, Line} -> Line
9797
end
9898
end.
99+
100+
%%-----------------------------------------------------------------------------
101+
%% @param Chars character(s) to write to console
102+
%% @returns ok
103+
%% @doc Writes the given character(s) to the console.
104+
%% @end
105+
%%-----------------------------------------------------------------------------
106+
-spec put_chars(Device :: any(), Chars :: list() | binary()) -> ok.
107+
put_chars(standard_error, Chars) ->
108+
put_chars(Chars);
109+
put_chars(standard_output, Chars) ->
110+
put_chars(Chars).

0 commit comments

Comments
 (0)