47
47
extern "C" {
48
48
#endif
49
49
50
- #define TERM_BOXED_VALUE_TAG 0x2
50
+ #define TERM_PRIMARY_MASK 0x3
51
+ #define TERM_PRIMARY_CP 0x0
52
+ #define TERM_PRIMARY_LIST 0x1
53
+ #define TERM_PRIMARY_BOXED 0x2
54
+ // #define TERM_PRIMARY_IMMED 0x3
55
+
56
+ #define TERM_BOXED_VALUE_TAG _Pragma ("TERM_BOXED_VALUE_TAG is deprecated, use TERM_PRIMARY_BOXED instead") TERM_PRIMARY_BOXED
51
57
52
58
#define TERM_IMMED_TAG_MASK 0xF
53
59
#define TERM_PID_TAG 0x3
@@ -61,7 +67,6 @@ extern "C" {
61
67
#define TERM_BOXED_REF 0x10
62
68
#define TERM_BOXED_FUN 0x14
63
69
#define TERM_BOXED_FLOAT 0x18
64
- #define TERM_CATCH_TAG 0x1B
65
70
#define TERM_BOXED_REFC_BINARY 0x20
66
71
#define TERM_BOXED_HEAP_BINARY 0x24
67
72
#define TERM_BOXED_SUB_BINARY 0x28
@@ -71,6 +76,12 @@ extern "C" {
71
76
#define TERM_BOXED_EXTERNAL_PORT 0x34
72
77
#define TERM_BOXED_EXTERNAL_REF 0x38
73
78
79
+ #define TERM_IMMED2_TAG_MASK 0x3F
80
+ #define TERM_IMMED2_TAG_SIZE 6
81
+ #define TERM_IMMED2_ATOM 0xB
82
+ #define TERM_IMMED2_CATCH 0x1B
83
+ #define TERM_NIL 0x3B
84
+
74
85
#define TERM_UNUSED 0x2B
75
86
#define TERM_RESERVED_MARKER (x ) ((x << 6) | TERM_UNUSED)
76
87
@@ -137,7 +148,7 @@ extern "C" {
137
148
138
149
#define TERM_DEBUG_ASSERT (...)
139
150
140
- #define TERM_FROM_ATOM_INDEX (atom_index ) ((atom_index << 6 ) | 0xB )
151
+ #define TERM_FROM_ATOM_INDEX (atom_index ) ((atom_index << TERM_IMMED2_TAG_SIZE ) | TERM_IMMED2_ATOM )
141
152
142
153
// Local ref is at most 30 bytes:
143
154
// 2^32-1 = 4294967295 (10 chars)
@@ -293,7 +304,7 @@ static inline const term *term_to_const_term_ptr(term t)
293
304
static inline bool term_is_atom (term t )
294
305
{
295
306
/* atom: | atom index | 00 10 11 */
296
- return ((t & TERM_BOXED_TAG_MASK ) == 0xB );
307
+ return ((t & TERM_IMMED2_TAG_MASK ) == TERM_IMMED2_ATOM );
297
308
}
298
309
299
310
/**
@@ -318,7 +329,7 @@ static inline bool term_is_invalid_term(term t)
318
329
static inline bool term_is_nil (term t )
319
330
{
320
331
/* nil: 11 10 11 */
321
- return ((t & TERM_BOXED_TAG_MASK ) == 0x3B );
332
+ return ((t & TERM_IMMED2_TAG_MASK ) == TERM_NIL );
322
333
}
323
334
324
335
/**
@@ -331,7 +342,7 @@ static inline bool term_is_nil(term t)
331
342
static inline bool term_is_nonempty_list (term t )
332
343
{
333
344
/* list: 01 */
334
- return ((t & 0x3 ) == 0x1 );
345
+ return ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_LIST );
335
346
}
336
347
337
348
/**
@@ -357,7 +368,7 @@ static inline bool term_is_list(term t)
357
368
static inline bool term_is_boxed (term t )
358
369
{
359
370
/* boxed: 10 */
360
- return ((t & 0x3 ) == 0x2 );
371
+ return ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED );
361
372
}
362
373
363
374
/**
@@ -383,7 +394,7 @@ static inline size_t term_get_size_from_boxed_header(term header)
383
394
static inline size_t term_boxed_size (term t )
384
395
{
385
396
/* boxed: 10 */
386
- TERM_DEBUG_ASSERT ((t & 0x3 ) == 0x2 );
397
+ TERM_DEBUG_ASSERT ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED );
387
398
388
399
const term * boxed_value = term_to_const_term_ptr (t );
389
400
return term_get_size_from_boxed_header (* boxed_value );
@@ -399,7 +410,7 @@ static inline size_t term_boxed_size(term t)
399
410
static inline bool term_is_binary (term t )
400
411
{
401
412
/* boxed: 10 */
402
- if ((t & 0x3 ) == 0x2 ) {
413
+ if ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_BOXED ) {
403
414
const term * boxed_value = term_to_const_term_ptr (t );
404
415
int masked_value = boxed_value [0 ] & TERM_BOXED_TAG_MASK ;
405
416
switch (masked_value ) {
@@ -521,7 +532,7 @@ static inline bool term_is_any_integer(term t)
521
532
522
533
static inline bool term_is_catch_label (term t )
523
534
{
524
- return (t & TERM_BOXED_TAG_MASK ) == TERM_CATCH_TAG ;
535
+ return (t & TERM_IMMED2_TAG_MASK ) == TERM_IMMED2_CATCH ;
525
536
}
526
537
527
538
/**
@@ -774,7 +785,7 @@ static inline bool term_is_external_fun(term t)
774
785
*/
775
786
static inline bool term_is_cp (term t )
776
787
{
777
- return ((t & 0x3 ) == 0 );
788
+ return ((t & TERM_PRIMARY_MASK ) == TERM_PRIMARY_CP );
778
789
}
779
790
780
791
/**
@@ -796,7 +807,7 @@ static inline term term_invalid_term()
796
807
*/
797
808
static inline term term_nil ()
798
809
{
799
- return 0x3B ;
810
+ return TERM_NIL ;
800
811
}
801
812
802
813
/**
@@ -1022,7 +1033,7 @@ static inline term term_make_boxed_int(avm_int_t value, Heap *heap)
1022
1033
term * boxed_int = memory_heap_alloc (heap , 1 + BOXED_TERMS_REQUIRED_FOR_INT );
1023
1034
boxed_int [0 ] = (BOXED_TERMS_REQUIRED_FOR_INT << 6 ) | TERM_BOXED_POSITIVE_INTEGER ; // OR sign bit
1024
1035
boxed_int [1 ] = value ;
1025
- return ((term ) boxed_int ) | TERM_BOXED_VALUE_TAG ;
1036
+ return ((term ) boxed_int ) | TERM_PRIMARY_BOXED ;
1026
1037
}
1027
1038
1028
1039
static inline term term_make_boxed_int64 (avm_int64_t large_int64 , Heap * heap )
@@ -1044,7 +1055,7 @@ static inline term term_make_boxed_int64(avm_int64_t large_int64, Heap *heap)
1044
1055
#else
1045
1056
#error "unsupported configuration."
1046
1057
#endif
1047
- return ((term ) boxed_int ) | TERM_BOXED_VALUE_TAG ;
1058
+ return ((term ) boxed_int ) | TERM_PRIMARY_BOXED ;
1048
1059
}
1049
1060
1050
1061
static inline term term_make_maybe_boxed_int64 (avm_int64_t value , Heap * heap )
@@ -1079,7 +1090,7 @@ static inline size_t term_boxed_integer_size(avm_int64_t value)
1079
1090
1080
1091
static inline term term_from_catch_label (unsigned int module_index , unsigned int label )
1081
1092
{
1082
- return (term ) ((module_index << 24 ) | (label << 6 ) | TERM_CATCH_TAG );
1093
+ return (term ) ((module_index << 24 ) | (label << 6 ) | TERM_IMMED2_CATCH );
1083
1094
}
1084
1095
1085
1096
/**
@@ -1228,7 +1239,7 @@ static inline term term_create_uninitialized_binary(size_t size, Heap *heap, Glo
1228
1239
boxed_value [0 ] = (size_in_terms << 6 ) | TERM_BOXED_HEAP_BINARY ;
1229
1240
boxed_value [1 ] = size ;
1230
1241
1231
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1242
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1232
1243
} else {
1233
1244
return term_alloc_refc_binary (size , false, heap , glb );
1234
1245
}
@@ -1416,7 +1427,7 @@ static inline term term_from_ref_ticks(uint64_t ref_ticks, Heap *heap)
1416
1427
#error "terms must be either 32 or 64 bit wide"
1417
1428
#endif
1418
1429
1419
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1430
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1420
1431
}
1421
1432
1422
1433
static inline uint64_t term_to_ref_ticks (term rt )
@@ -1460,7 +1471,7 @@ static inline term term_make_external_process_id(term node, uint32_t process_id,
1460
1471
external_thing_words [2 ] = process_id ;
1461
1472
external_thing_words [3 ] = serial ;
1462
1473
1463
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1474
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1464
1475
}
1465
1476
1466
1477
/**
@@ -1484,7 +1495,7 @@ static inline term term_make_external_port_number(term node, uint64_t number, ui
1484
1495
external_thing_words [2 ] = number >> 32 ;
1485
1496
external_thing_words [3 ] = (uint32_t ) number ;
1486
1497
1487
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1498
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1488
1499
}
1489
1500
1490
1501
/**
@@ -1600,7 +1611,7 @@ static inline term term_make_external_reference(term node, uint16_t len, uint32_
1600
1611
#error "terms must be either 32 or 64 bit wide"
1601
1612
#endif
1602
1613
1603
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1614
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1604
1615
}
1605
1616
1606
1617
/**
@@ -1666,7 +1677,7 @@ static inline term term_alloc_tuple(uint32_t size, Heap *heap)
1666
1677
term * boxed_value = memory_heap_alloc (heap , 1 + size );
1667
1678
boxed_value [0 ] = (size << 6 ); //tuple
1668
1679
1669
- return ((term ) boxed_value ) | 0x2 ;
1680
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1670
1681
}
1671
1682
1672
1683
/**
@@ -1740,7 +1751,7 @@ static inline term term_from_string(const uint8_t *data, uint16_t size, Heap *he
1740
1751
list_cells [i ] = (term ) & list_cells [i + 2 ] | 0x1 ;
1741
1752
list_cells [i + 1 ] = term_from_int11 (data [i / 2 ]);
1742
1753
}
1743
- list_cells [size * 2 - 2 ] = 0x3B ;
1754
+ list_cells [size * 2 - 2 ] = TERM_NIL ;
1744
1755
1745
1756
return ((term ) list_cells ) | 0x1 ;
1746
1757
}
@@ -1876,7 +1887,7 @@ static inline term term_from_float(avm_float_t f, Heap *heap)
1876
1887
float_term_t * boxed_float = (float_term_t * ) (boxed_value + 1 );
1877
1888
boxed_float -> f = f ;
1878
1889
1879
- return ((term ) boxed_value ) | TERM_BOXED_VALUE_TAG ;
1890
+ return ((term ) boxed_value ) | TERM_PRIMARY_BOXED ;
1880
1891
}
1881
1892
1882
1893
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