switched bitfields to bit-manipulation macros
This commit is contained in:
@ -38,8 +38,8 @@
|
||||
#define STIX_ASSERT(x) assert(x)
|
||||
|
||||
#define STIX_ALIGN(x,y) ((((x) + (y) - 1) / (y)) * (y))
|
||||
/* make a low bit mask that can mask off low n bits*/
|
||||
#define STIX_LBMASK(type,n) (~(~((type)0) << (n)))
|
||||
|
||||
|
||||
|
||||
/* ========================================================================= */
|
||||
/* CLASS */
|
||||
@ -63,33 +63,43 @@ typedef struct stix_class_t stix_class_t;
|
||||
typedef struct stix_class_t* stix_oop_class_t;
|
||||
|
||||
/*
|
||||
* The spec field of a class object encodes the size of the fixed part
|
||||
* The spec field of a class object encodes the number of the fixed part
|
||||
* and the type of the variable part. The fixed part is the number of
|
||||
* instance variables. The variable part can be specified when the object
|
||||
* is instantiated if it is variadic.
|
||||
*
|
||||
* vtype is one of the #stix_obj_type_t enumerators.
|
||||
* indexed_type is one of the #stix_obj_type_t enumerators.
|
||||
*
|
||||
* The maximum number of named(fixed) instance variables for a class is:
|
||||
* 2 ^ (BITS-IN-OOW - STIX_OBJ_TYPE_BITS - 1)
|
||||
*
|
||||
* The number of named instance variables can be greater than 0 if the class
|
||||
* is not variable or if it's a variable-pointer class(vtype == STIX_OBJ_TYPE_OOP)
|
||||
*
|
||||
* See also #stix_obj_type_t.
|
||||
* The number of named instance variables can be greater than 0 if the
|
||||
* class spec is not indexed or if it's a pointer indexed class
|
||||
* (indexed_type == STIX_OBJ_TYPE_OOP)
|
||||
*/
|
||||
#define STIX_CLASS_SPEC_MAKE(fixed,variadic,vtype) ( \
|
||||
(((stix_oow_t)(fixed)) << (STIX_OBJ_TYPE_BITS + 1)) | \
|
||||
(((stix_oow_t)(vtype)) << 1) | (((stix_oow_t)variadic) & 1) )
|
||||
#define STIX_CLASS_SPEC_MAKE(named_instvar,is_indexed,indexed_type) ( \
|
||||
(((stix_oow_t)(named_instvar)) << (STIX_OBJ_TYPE_BITS + 1)) | \
|
||||
(((stix_oow_t)(indexed_type)) << 1) | (((stix_oow_t)is_indexed) & 1) )
|
||||
|
||||
/* what is the number of named instance variables? */
|
||||
#define STIX_CLASS_SPEC_FIXED(spec) ((spec) >> STIX_OBJ_TYPE_BITS)
|
||||
#define STIX_CLASS_SPEC_NAMED_INSTVAR(spec) ((spec) >> STIX_OBJ_FLAGS_TYPE_BITS)
|
||||
|
||||
/* is a variable class? */
|
||||
#define STIX_CLASS_SPEC_ISVAR(spec) ((spec) & 1)
|
||||
/* is it a user-indexable class?
|
||||
* all objects can be indexed with basicAt:.
|
||||
* this indicates if an object can be instantiated with a dynamic size
|
||||
* (new: size) and and can be indexed with at:.
|
||||
*/
|
||||
#define STIX_CLASS_SPEC_IS_INDEXED(spec) ((spec) & 1)
|
||||
|
||||
/* if so, what variable class is it? variable-character? variable-pointer? etc? */
|
||||
#define STIX_CLASS_SPEC_VTYPE(spec) ((spec) & (STIX_LBMASK(stix_oow_t, STIX_OBJ_TYPE_BITS) << 1))
|
||||
/* if so, what is the indexing type? character? pointer? etc? */
|
||||
#define STIX_CLASS_SPEC_INDEXED_TYPE(spec) ((spec) & (STIX_LBMASK(stix_oow_t, STIX_OBJ_FLAGS_TYPE_BITS) << 1))
|
||||
|
||||
|
||||
/* 2 ^ (BITS-IN-OOW - STIX_OBJ_TYPE_BITS - 1) */
|
||||
#define STIX_MAX_NAMED_INSTVAR ((stix_oow_t)2 << (STIX_SIZEOF(stix_oow_t) * 8 - (STIX_OBJ_FLAGS_TYPE_BITS + 1) - 1))
|
||||
/* Given the number of named instance variables, what is the maximum number
|
||||
* of indexed slots? */
|
||||
#define STIX_MAX_INDEXED_COUNT(named_instvar) ((~(stix_oow_t)0) - named_instvar)
|
||||
|
||||
/* VM-level macros */
|
||||
#define STIX_CLASSOF(stix,oop) \
|
||||
@ -147,6 +157,11 @@ void* stix_allocheapmem (
|
||||
/* ========================================================================= */
|
||||
/* obj.c */
|
||||
/* ========================================================================= */
|
||||
void* stix_allocbytes (
|
||||
stix_t* stix,
|
||||
stix_size_t size
|
||||
);
|
||||
|
||||
stix_oop_t stix_allocoopobj (
|
||||
stix_t* stix,
|
||||
stix_oow_t size
|
||||
@ -170,6 +185,7 @@ stix_oop_t stix_allocuint16obj (
|
||||
stix_oow_t len
|
||||
);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user