48
48
extern "C" {
49
49
#endif
50
50
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
52
58
53
59
#define TERM_IMMED_TAG_MASK 0xF
54
60
#define TERM_PID_TAG 0x3
@@ -62,7 +68,6 @@ extern "C" {
62
68
#define TERM_BOXED_REF 0x10
63
69
#define TERM_BOXED_FUN 0x14
64
70
#define TERM_BOXED_FLOAT 0x18
65
- #define TERM_CATCH_TAG 0x1B
66
71
#define TERM_BOXED_REFC_BINARY 0x20
67
72
#define TERM_BOXED_HEAP_BINARY 0x24
68
73
#define TERM_BOXED_SUB_BINARY 0x28
@@ -72,6 +77,12 @@ extern "C" {
72
77
#define TERM_BOXED_EXTERNAL_PORT 0x34
73
78
#define TERM_BOXED_EXTERNAL_REF 0x38
74
79
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
+
75
86
#define TERM_UNUSED 0x2B
76
87
#define TERM_RESERVED_MARKER (x ) ((x << 6) | TERM_UNUSED)
77
88
@@ -138,7 +149,7 @@ extern "C" {
138
149
139
150
#define TERM_DEBUG_ASSERT (...)
140
151
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 )
142
153
143
154
// Local ref is at most 30 bytes:
144
155
// 2^32-1 = 4294967295 (10 chars)
@@ -294,7 +305,7 @@ static inline const term *term_to_const_term_ptr(term t)
294
305
static inline bool term_is_atom (term t )
295
306
{
296
307
/* atom: | atom index | 00 10 11 */
297
- return ((t & TERM_BOXED_TAG_MASK ) == 0xB );
308
+ return ((t & TERM_IMMED2_TAG_MASK ) == TERM_IMMED2_ATOM );
298
309
}
299
310
300
311
/**
@@ -319,7 +330,7 @@ static inline bool term_is_invalid_term(term t)
319
330
static inline bool term_is_nil (term t )
320
331
{
321
332
/* nil: 11 10 11 */
322
- return ((t & TERM_BOXED_TAG_MASK ) == 0x3B );
333
+ return ((t & TERM_IMMED2_TAG_MASK ) == TERM_NIL );
323
334
}
324
335
325
336
/**
@@ -332,7 +343,7 @@ static inline bool term_is_nil(term t)
332
343
static inline bool term_is_nonempty_list (term t )
333
344
{
334
345
/* list: 01 */
335
- return ((t & 0x3 ) == 0x1 );
346
+ return ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_LIST );
336
347
}
337
348
338
349
/**
@@ -358,7 +369,7 @@ static inline bool term_is_list(term t)
358
369
static inline bool term_is_boxed (term t )
359
370
{
360
371
/* boxed: 10 */
361
- return ((t & 0x3 ) == 0x2 );
372
+ return ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED );
362
373
}
363
374
364
375
/**
@@ -384,7 +395,7 @@ static inline size_t term_get_size_from_boxed_header(term header)
384
395
static inline size_t term_boxed_size (term t )
385
396
{
386
397
/* boxed: 10 */
387
- TERM_DEBUG_ASSERT ((t & 0x3 ) == 0x2 );
398
+ TERM_DEBUG_ASSERT ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED );
388
399
389
400
const term * boxed_value = term_to_const_term_ptr (t );
390
401
return term_get_size_from_boxed_header (* boxed_value );
@@ -400,7 +411,7 @@ static inline size_t term_boxed_size(term t)
400
411
static inline bool term_is_binary (term t )
401
412
{
402
413
/* boxed: 10 */
403
- if ((t & 0x3 ) == 0x2 ) {
414
+ if ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED ) {
404
415
const term * boxed_value = term_to_const_term_ptr (t );
405
416
int masked_value = boxed_value [0 ] & TERM_BOXED_TAG_MASK ;
406
417
switch (masked_value ) {
@@ -522,7 +533,7 @@ static inline bool term_is_any_integer(term t)
522
533
523
534
static inline bool term_is_catch_label (term t )
524
535
{
525
- return (t & TERM_BOXED_TAG_MASK ) == TERM_CATCH_TAG ;
536
+ return (t & TERM_IMMED2_TAG_MASK ) == TERM_IMMED2_CATCH ;
526
537
}
527
538
528
539
/**
@@ -775,7 +786,7 @@ static inline bool term_is_external_fun(term t)
775
786
*/
776
787
static inline bool term_is_cp (term t )
777
788
{
778
- return ((t & 0x3 ) == 0 );
789
+ return ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_CP );
779
790
}
780
791
781
792
/**
@@ -797,7 +808,7 @@ static inline term term_invalid_term()
797
808
*/
798
809
static inline term term_nil ()
799
810
{
800
- return 0x3B ;
811
+ return TERM_NIL ;
801
812
}
802
813
803
814
/**
@@ -1023,7 +1034,7 @@ static inline term term_make_boxed_int(avm_int_t value, Heap *heap)
1023
1034
term * boxed_int = memory_heap_alloc (heap , 1 + BOXED_TERMS_REQUIRED_FOR_INT );
1024
1035
boxed_int [0 ] = (BOXED_TERMS_REQUIRED_FOR_INT << 6 ) | TERM_BOXED_POSITIVE_INTEGER ; // OR sign bit
1025
1036
boxed_int [1 ] = value ;
1026
- return ((term ) boxed_int ) | TERM_BOXED_VALUE_TAG ;
1037
+ return ((term ) boxed_int ) | TERM_PRIMARY_BOXED ;
1027
1038
}
1028
1039
1029
1040
static 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)
1045
1056
#else
1046
1057
#error "unsupported configuration."
1047
1058
#endif
1048
- return ((term ) boxed_int ) | TERM_BOXED_VALUE_TAG ;
1059
+ return ((term ) boxed_int ) | TERM_PRIMARY_BOXED ;
1049
1060
}
1050
1061
1051
1062
static 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)
1080
1091
1081
1092
static inline term term_from_catch_label (unsigned int module_index , unsigned int label )
1082
1093
{
1083
- return (term ) ((module_index << 24 ) | (label << 6 ) | TERM_CATCH_TAG );
1094
+ return (term ) ((module_index << 24 ) | (label << 6 ) | TERM_IMMED2_CATCH );
1084
1095
}
1085
1096
1086
1097
/**
@@ -1229,7 +1240,7 @@ static inline term term_create_uninitialized_binary(size_t size, Heap *heap, Glo
1229
1240
boxed_value [0 ] = (size_in_terms << 6 ) | TERM_BOXED_HEAP_BINARY ;
1230
1241
boxed_value [1 ] = size ;
1231
1242
1232
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1243
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1233
1244
} else {
1234
1245
return term_alloc_refc_binary (size , false, heap , glb );
1235
1246
}
@@ -1417,7 +1428,7 @@ static inline term term_from_ref_ticks(uint64_t ref_ticks, Heap *heap)
1417
1428
#error "terms must be either 32 or 64 bit wide"
1418
1429
#endif
1419
1430
1420
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1431
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1421
1432
}
1422
1433
1423
1434
static 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,
1461
1472
external_thing_words [2 ] = process_id ;
1462
1473
external_thing_words [3 ] = serial ;
1463
1474
1464
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1475
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1465
1476
}
1466
1477
1467
1478
/**
@@ -1485,7 +1496,7 @@ static inline term term_make_external_port_number(term node, uint64_t number, ui
1485
1496
external_thing_words [2 ] = number >> 32 ;
1486
1497
external_thing_words [3 ] = (uint32_t ) number ;
1487
1498
1488
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1499
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1489
1500
}
1490
1501
1491
1502
/**
@@ -1601,7 +1612,7 @@ static inline term term_make_external_reference(term node, uint16_t len, uint32_
1601
1612
#error "terms must be either 32 or 64 bit wide"
1602
1613
#endif
1603
1614
1604
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1615
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1605
1616
}
1606
1617
1607
1618
/**
@@ -1667,7 +1678,7 @@ static inline term term_alloc_tuple(uint32_t size, Heap *heap)
1667
1678
term * boxed_value = memory_heap_alloc (heap , 1 + size );
1668
1679
boxed_value [0 ] = (size << 6 ); //tuple
1669
1680
1670
- return ((term ) boxed_value ) | 0x2 ;
1681
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1671
1682
}
1672
1683
1673
1684
/**
@@ -1741,7 +1752,7 @@ static inline term term_from_string(const uint8_t *data, uint16_t size, Heap *he
1741
1752
list_cells [i ] = (term ) & list_cells [i + 2 ] | 0x1 ;
1742
1753
list_cells [i + 1 ] = term_from_int11 (data [i / 2 ]);
1743
1754
}
1744
- list_cells [size * 2 - 2 ] = 0x3B ;
1755
+ list_cells [size * 2 - 2 ] = TERM_NIL ;
1745
1756
1746
1757
return ((term ) list_cells ) | 0x1 ;
1747
1758
}
@@ -1877,7 +1888,7 @@ static inline term term_from_float(avm_float_t f, Heap *heap)
1877
1888
float_term_t * boxed_float = (float_term_t * ) (boxed_value + 1 );
1878
1889
boxed_float -> f = f ;
1879
1890
1880
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1891
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1881
1892
}
1882
1893
1883
1894
static 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
1985
1996
boxed_func [2 ] = f ;
1986
1997
boxed_func [3 ] = a ;
1987
1998
1988
- return ((term ) boxed_func ) | TERM_BOXED_VALUE_TAG ;
1999
+ return ((term ) boxed_func ) | TERM_PRIMARY_BOXED ;
1989
2000
}
1990
2001
1991
2002
static 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
2066
2077
}
2067
2078
}
2068
2079
2069
- return ((term ) boxed_match_state ) | TERM_BOXED_VALUE_TAG ;
2080
+ return ((term ) boxed_match_state ) | TERM_PRIMARY_BOXED ;
2070
2081
}
2071
2082
2072
2083
/**
@@ -2080,7 +2091,7 @@ static inline term term_alloc_bin_match_state(term binary_or_state, int slots, H
2080
2091
static inline void term_truncate_boxed (term boxed , size_t new_size , Heap * heap )
2081
2092
{
2082
2093
/* boxed: 10 */
2083
- TERM_DEBUG_ASSERT ((t & 0x3 ) == 0x2 );
2094
+ TERM_DEBUG_ASSERT ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED );
2084
2095
2085
2096
term * boxed_value = term_to_term_ptr (boxed );
2086
2097
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
2127
2138
boxed_value [0 ] = ((1 + size ) << 6 ) | TERM_BOXED_MAP ;
2128
2139
boxed_value [term_get_map_keys_offset ()] = keys ;
2129
2140
2130
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
2141
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
2131
2142
}
2132
2143
2133
2144
static 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)
2229
2240
boxed_value [0 ] = ((TERM_BOXED_REFC_BINARY_SIZE - 1 ) << 6 ) | TERM_BOXED_REFC_BINARY ;
2230
2241
boxed_value [1 ] = (term ) 0 ; // binary size, this is pre ERTS 9.0 (OTP-20.0) behavior
2231
2242
boxed_value [2 ] = (term ) RefcNoFlags ;
2232
- term ret = ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
2243
+ term ret = ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
2233
2244
boxed_value [3 ] = (term ) refc ;
2234
2245
// Add the resource to the mso list
2235
2246
refc -> ref_count ++ ;
0 commit comments