-
Notifications
You must be signed in to change notification settings - Fork 122
Use TERM_PRIMARY_* and TERM_IMMED* macros, following erl_term.h #1701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind leaving a couple of lines of explanation in the commit message about why we are making this change?
f374948
to
9ce5c26
Compare
@@ -2080,7 +2091,7 @@ static inline term term_alloc_bin_match_state(term binary_or_state, int slots, H | |||
static inline void term_truncate_boxed(term boxed, size_t new_size, Heap *heap) | |||
{ | |||
/* boxed: 10 */ | |||
TERM_DEBUG_ASSERT((t & 0x3) == 0x2); | |||
TERM_DEBUG_ASSERT((t & TERM_PRIMARY_MASK) == TERM_PRIMARY_BOXED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t
-> boxed
memory.c had a missing semicolon, get/put_tuple_element in term.h unpacked header directly instead of using function. Additionally, first condition is already checked by term_is_tuple(). There's one unfixed assert TERM_DEBUG_ASSERT((t & 0x3) == 0x2); but fixing it would create conflicts with atomvm#1701 (changes magic values to macros). Signed-off-by: Jakub Gonet <jakub.gonet@swmansion.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, makes sense. My last comment on this topic:
I'm not strongly opinionated about this, but the suffix _TAG
makes more clear that is a marker that is applied on top of something else.
such as TERM_PRIMARY_BOXED
-> TERM_PRIMARY_BOXED_TAG
.
Anyway as soon as it is rebased it can be merged.
Erlang/OTP's erl_term.h defines several macros to encode terms and distinguishes `TAG_PRIMARY_*` for the two lowest bits, `_TAG_IMMED1*` for the lowest four bits and `_TAG_IMMED2*` for the lowest six bits. AtomVM term.h uses `TERM_BOXED_*` for the first word of boxed items. It used magic number `0x2` or `TERM_BOXED_VALUE_TAG` instead of what erl_term.h calls `TAG_PRIMARY_BOXED`, which is confusing as it's not related to the first word of boxed item but to the (lowest two bits of the) term itself. This change introduces `TERM_PRIMARY_*` macros following Erlang/OTP erl_term.h's `TAG_PRIMARY_*` macros, and replaces all matching magic numbers with these macros. It also introduces `TERM_IMMED2_*` macros and uses them instead of magic numbers. `TERM_BOXED_VALUE_TAG` is marked as deprecated but kept. No macro called `TERM_IMMED1_*` is introduced as AtomVM already uses non-confusing macros `TERM_PID_TAG`, `TERM_PORT_TAG` and `TERM_INTEGER_TAG`. Signed-off-by: Paul Guyot <pguyot@kallisys.net>
9ce5c26
to
ea687ad
Compare
Erlang/OTP's erl_term.h defines several macros to encode terms and
distinguishes
TAG_PRIMARY_*
for the two lowest bits,_TAG_IMMED1*
forthe lowest four bits and
_TAG_IMMED2*
for the lowest six bits.AtomVM term.h uses
TERM_BOXED_*
for the first word of boxed items.It used magic number
0x2
orTERM_BOXED_VALUE_TAG
instead of whaterl_term.h calls
TAG_PRIMARY_BOXED
, which is confusing as it's not relatedto the first word of boxed item but to the (lowest two bits of the) term itself.
This change introduces
TERM_PRIMARY_*
macros following Erlang/OTP erl_term.h'sTAG_PRIMARY_*
macros, and replaces all matching magic numbers with thesemacros.
It also introduces
TERM_IMMED2_*
macros and uses them instead of magicnumbers.
TERM_BOXED_VALUE_TAG
is marked as deprecated but kept.No macro called
TERM_IMMED1_*
is introduced as AtomVM already usesnon-confusing macros
TERM_PID_TAG
,TERM_PORT_TAG
andTERM_INTEGER_TAG
.These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later