4848extern "C" {
4949#endif
5050
51- #define TERM_BOXED_VALUE_TAG 0x2
51+ #define TERM_PRIMARY_MASK 0x3
52+ #define TERM_PRIMARY_CP 0x0
53+ #define TERM_PRIMARY_LIST 0x1
54+ #define TERM_PRIMARY_BOXED 0x2
55+ // #define TERM_PRIMARY_IMMED 0x3
56+
57+ #define TERM_BOXED_VALUE_TAG _Pragma ("TERM_BOXED_VALUE_TAG is deprecated, use TERM_PRIMARY_BOXED instead") TERM_PRIMARY_BOXED
5258
5359#define TERM_IMMED_TAG_MASK 0xF
5460#define TERM_PID_TAG 0x3
@@ -62,7 +68,6 @@ extern "C" {
6268#define TERM_BOXED_REF 0x10
6369#define TERM_BOXED_FUN 0x14
6470#define TERM_BOXED_FLOAT 0x18
65- #define TERM_CATCH_TAG 0x1B
6671#define TERM_BOXED_REFC_BINARY 0x20
6772#define TERM_BOXED_HEAP_BINARY 0x24
6873#define TERM_BOXED_SUB_BINARY 0x28
@@ -72,6 +77,12 @@ extern "C" {
7277#define TERM_BOXED_EXTERNAL_PORT 0x34
7378#define TERM_BOXED_EXTERNAL_REF 0x38
7479
80+ #define TERM_IMMED2_TAG_MASK 0x3F
81+ #define TERM_IMMED2_TAG_SIZE 6
82+ #define TERM_IMMED2_ATOM 0xB
83+ #define TERM_IMMED2_CATCH 0x1B
84+ #define TERM_NIL 0x3B
85+
7586#define TERM_UNUSED 0x2B
7687#define TERM_RESERVED_MARKER (x ) ((x << 6) | TERM_UNUSED)
7788
@@ -138,7 +149,7 @@ extern "C" {
138149
139150#define TERM_DEBUG_ASSERT (...)
140151
141- #define TERM_FROM_ATOM_INDEX (atom_index ) ((atom_index << 6 ) | 0xB )
152+ #define TERM_FROM_ATOM_INDEX (atom_index ) ((atom_index << TERM_IMMED2_TAG_SIZE ) | TERM_IMMED2_ATOM )
142153
143154// Local ref is at most 30 bytes:
144155// 2^32-1 = 4294967295 (10 chars)
@@ -294,7 +305,7 @@ static inline const term *term_to_const_term_ptr(term t)
294305static inline bool term_is_atom (term t )
295306{
296307 /* atom: | atom index | 00 10 11 */
297- return ((t & TERM_BOXED_TAG_MASK ) == 0xB );
308+ return ((t & TERM_IMMED2_TAG_MASK ) == TERM_IMMED2_ATOM );
298309}
299310
300311/**
@@ -319,7 +330,7 @@ static inline bool term_is_invalid_term(term t)
319330static inline bool term_is_nil (term t )
320331{
321332 /* nil: 11 10 11 */
322- return ((t & TERM_BOXED_TAG_MASK ) == 0x3B );
333+ return ((t & TERM_IMMED2_TAG_MASK ) == TERM_NIL );
323334}
324335
325336/**
@@ -332,7 +343,7 @@ static inline bool term_is_nil(term t)
332343static inline bool term_is_nonempty_list (term t )
333344{
334345 /* list: 01 */
335- return ((t & 0x3 ) == 0x1 );
346+ return ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_LIST );
336347}
337348
338349/**
@@ -358,7 +369,7 @@ static inline bool term_is_list(term t)
358369static inline bool term_is_boxed (term t )
359370{
360371 /* boxed: 10 */
361- return ((t & 0x3 ) == 0x2 );
372+ return ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED );
362373}
363374
364375/**
@@ -384,7 +395,7 @@ static inline size_t term_get_size_from_boxed_header(term header)
384395static inline size_t term_boxed_size (term t )
385396{
386397 /* boxed: 10 */
387- TERM_DEBUG_ASSERT ((t & 0x3 ) == 0x2 );
398+ TERM_DEBUG_ASSERT ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED );
388399
389400 const term * boxed_value = term_to_const_term_ptr (t );
390401 return term_get_size_from_boxed_header (* boxed_value );
@@ -400,7 +411,7 @@ static inline size_t term_boxed_size(term t)
400411static inline bool term_is_binary (term t )
401412{
402413 /* boxed: 10 */
403- if ((t & 0x3 ) == 0x2 ) {
414+ if ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED ) {
404415 const term * boxed_value = term_to_const_term_ptr (t );
405416 int masked_value = boxed_value [0 ] & TERM_BOXED_TAG_MASK ;
406417 switch (masked_value ) {
@@ -522,7 +533,7 @@ static inline bool term_is_any_integer(term t)
522533
523534static inline bool term_is_catch_label (term t )
524535{
525- return (t & TERM_BOXED_TAG_MASK ) == TERM_CATCH_TAG ;
536+ return (t & TERM_IMMED2_TAG_MASK ) == TERM_IMMED2_CATCH ;
526537}
527538
528539/**
@@ -775,7 +786,7 @@ static inline bool term_is_external_fun(term t)
775786 */
776787static inline bool term_is_cp (term t )
777788{
778- return ((t & 0x3 ) == 0 );
789+ return ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_CP );
779790}
780791
781792/**
@@ -797,7 +808,7 @@ static inline term term_invalid_term()
797808 */
798809static inline term term_nil ()
799810{
800- return 0x3B ;
811+ return TERM_NIL ;
801812}
802813
803814/**
@@ -1023,7 +1034,7 @@ static inline term term_make_boxed_int(avm_int_t value, Heap *heap)
10231034 term * boxed_int = memory_heap_alloc (heap , 1 + BOXED_TERMS_REQUIRED_FOR_INT );
10241035 boxed_int [0 ] = (BOXED_TERMS_REQUIRED_FOR_INT << 6 ) | TERM_BOXED_POSITIVE_INTEGER ; // OR sign bit
10251036 boxed_int [1 ] = value ;
1026- return ((term ) boxed_int ) | TERM_BOXED_VALUE_TAG ;
1037+ return ((term ) boxed_int ) | TERM_PRIMARY_BOXED ;
10271038}
10281039
10291040static inline term term_make_boxed_int64 (avm_int64_t large_int64 , Heap * heap )
@@ -1045,7 +1056,7 @@ static inline term term_make_boxed_int64(avm_int64_t large_int64, Heap *heap)
10451056 #else
10461057 #error "unsupported configuration."
10471058 #endif
1048- return ((term ) boxed_int ) | TERM_BOXED_VALUE_TAG ;
1059+ return ((term ) boxed_int ) | TERM_PRIMARY_BOXED ;
10491060}
10501061
10511062static inline term term_make_maybe_boxed_int64 (avm_int64_t value , Heap * heap )
@@ -1080,7 +1091,7 @@ static inline size_t term_boxed_integer_size(avm_int64_t value)
10801091
10811092static inline term term_from_catch_label (unsigned int module_index , unsigned int label )
10821093{
1083- return (term ) ((module_index << 24 ) | (label << 6 ) | TERM_CATCH_TAG );
1094+ return (term ) ((module_index << 24 ) | (label << 6 ) | TERM_IMMED2_CATCH );
10841095}
10851096
10861097/**
@@ -1229,7 +1240,7 @@ static inline term term_create_uninitialized_binary(size_t size, Heap *heap, Glo
12291240 boxed_value [0 ] = (size_in_terms << 6 ) | TERM_BOXED_HEAP_BINARY ;
12301241 boxed_value [1 ] = size ;
12311242
1232- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1243+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
12331244 } else {
12341245 return term_alloc_refc_binary (size , false, heap , glb );
12351246 }
@@ -1417,7 +1428,7 @@ static inline term term_from_ref_ticks(uint64_t ref_ticks, Heap *heap)
14171428 #error "terms must be either 32 or 64 bit wide"
14181429 #endif
14191430
1420- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1431+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
14211432}
14221433
14231434static inline uint64_t term_to_ref_ticks (term rt )
@@ -1461,7 +1472,7 @@ static inline term term_make_external_process_id(term node, uint32_t process_id,
14611472 external_thing_words [2 ] = process_id ;
14621473 external_thing_words [3 ] = serial ;
14631474
1464- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1475+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
14651476}
14661477
14671478/**
@@ -1485,7 +1496,7 @@ static inline term term_make_external_port_number(term node, uint64_t number, ui
14851496 external_thing_words [2 ] = number >> 32 ;
14861497 external_thing_words [3 ] = (uint32_t ) number ;
14871498
1488- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1499+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
14891500}
14901501
14911502/**
@@ -1601,7 +1612,7 @@ static inline term term_make_external_reference(term node, uint16_t len, uint32_
16011612 #error "terms must be either 32 or 64 bit wide"
16021613 #endif
16031614
1604- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1615+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
16051616}
16061617
16071618/**
@@ -1667,7 +1678,7 @@ static inline term term_alloc_tuple(uint32_t size, Heap *heap)
16671678 term * boxed_value = memory_heap_alloc (heap , 1 + size );
16681679 boxed_value [0 ] = (size << 6 ); //tuple
16691680
1670- return ((term ) boxed_value ) | 0x2 ;
1681+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
16711682}
16721683
16731684/**
@@ -1741,7 +1752,7 @@ static inline term term_from_string(const uint8_t *data, uint16_t size, Heap *he
17411752 list_cells [i ] = (term ) & list_cells [i + 2 ] | 0x1 ;
17421753 list_cells [i + 1 ] = term_from_int11 (data [i / 2 ]);
17431754 }
1744- list_cells [size * 2 - 2 ] = 0x3B ;
1755+ list_cells [size * 2 - 2 ] = TERM_NIL ;
17451756
17461757 return ((term ) list_cells ) | 0x1 ;
17471758}
@@ -1877,7 +1888,7 @@ static inline term term_from_float(avm_float_t f, Heap *heap)
18771888 float_term_t * boxed_float = (float_term_t * ) (boxed_value + 1 );
18781889 boxed_float -> f = f ;
18791890
1880- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1891+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
18811892}
18821893
18831894static inline avm_float_t term_to_float (term t )
@@ -1985,7 +1996,7 @@ static inline term term_make_function_reference(term m, term f, term a, Heap *he
19851996 boxed_func [2 ] = f ;
19861997 boxed_func [3 ] = a ;
19871998
1988- return ((term ) boxed_func ) | TERM_BOXED_VALUE_TAG ;
1999+ return ((term ) boxed_func ) | TERM_PRIMARY_BOXED ;
19892000}
19902001
19912002static inline bool term_is_match_state (term t )
@@ -2066,7 +2077,7 @@ static inline term term_alloc_bin_match_state(term binary_or_state, int slots, H
20662077 }
20672078 }
20682079
2069- return ((term ) boxed_match_state ) | TERM_BOXED_VALUE_TAG ;
2080+ return ((term ) boxed_match_state ) | TERM_PRIMARY_BOXED ;
20702081}
20712082
20722083/**
@@ -2080,7 +2091,7 @@ static inline term term_alloc_bin_match_state(term binary_or_state, int slots, H
20802091static inline void term_truncate_boxed (term boxed , size_t new_size , Heap * heap )
20812092{
20822093 /* boxed: 10 */
2083- TERM_DEBUG_ASSERT ((t & 0x3 ) == 0x2 );
2094+ TERM_DEBUG_ASSERT ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED );
20842095
20852096 term * boxed_value = term_to_term_ptr (boxed );
20862097 int size_diff = (boxed_value [0 ] >> 6 ) - new_size ;
@@ -2127,7 +2138,7 @@ static inline term term_alloc_map_maybe_shared(avm_uint_t size, term keys, Heap
21272138 boxed_value [0 ] = ((1 + size ) << 6 ) | TERM_BOXED_MAP ;
21282139 boxed_value [term_get_map_keys_offset ()] = keys ;
21292140
2130- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
2141+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
21312142}
21322143
21332144static inline term term_alloc_map (avm_uint_t size , Heap * heap )
@@ -2229,7 +2240,7 @@ static inline term term_from_resource(void *resource, Heap *heap)
22292240 boxed_value [0 ] = ((TERM_BOXED_REFC_BINARY_SIZE - 1 ) << 6 ) | TERM_BOXED_REFC_BINARY ;
22302241 boxed_value [1 ] = (term ) 0 ; // binary size, this is pre ERTS 9.0 (OTP-20.0) behavior
22312242 boxed_value [2 ] = (term ) RefcNoFlags ;
2232- term ret = ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
2243+ term ret = ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
22332244 boxed_value [3 ] = (term ) refc ;
22342245 // Add the resource to the mso list
22352246 refc -> ref_count ++ ;
0 commit comments