Skip to content

Commit

Permalink
Allow sending messages to registered process with !
Browse files Browse the repository at this point in the history
Enables sending messages to registered processes using the shorhand `!`
operator. If a message is sent to an atom name that is not registered using the
`!` operator a `badarg` run-time error occurs, matching OTP behaviour.

closes atomvm#1011
closes atomvm#98

Signed-off-by: Winford <winford@object.stream>
  • Loading branch information
UncleGrumpy committed Feb 18, 2024
1 parent 15e0fb0 commit 447795f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- ESP32: fix i2c_driver_acquire and i2c_driver_release functions, that were working only once.
- Sending messages to registered processes using the `!` operator now works.

## [0.6.0-beta.0] - 2024-02-08

Expand Down
11 changes: 10 additions & 1 deletion src/libAtomVM/opcodesswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2213,7 +2213,16 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
#endif

#ifdef IMPL_EXECUTE_LOOP
int local_process_id = term_to_local_process_id(x_regs[0]);
term process_term = x_regs[0];
int local_process_id;
if (term_is_atom(process_term)) {
local_process_id = globalcontext_get_registered_process(ctx->global, term_to_atom_index(process_term));
if (UNLIKELY(local_process_id == 0 )){
RAISE_ERROR(BADARG_ATOM);
}
} else {
local_process_id = term_to_local_process_id(process_term);
}
TRACE("send/0 target_pid=%i\n", local_process_id);
TRACE_SEND(ctx, x_regs[0], x_regs[1]);
globalcontext_send_message(ctx->global, local_process_id, x_regs[1]);
Expand Down

0 comments on commit 447795f

Please sign in to comment.