switched bitfields to bit-manipulation macros

This commit is contained in:
hyunghwan.chung 2015-05-03 17:10:30 +00:00
parent 6e9a47fd5b
commit e637f3a1f1
5 changed files with 200 additions and 99 deletions

View File

@ -87,7 +87,7 @@ static stix_oop_t move_one (stix_t* stix, stix_oop_t oop)
{ {
STIX_ASSERT (STIX_OOP_IS_POINTER(oop)); STIX_ASSERT (STIX_OOP_IS_POINTER(oop));
if (oop->flags & STIX_OBJ_FLAG_MOVED) if (STIX_OBJ_GET_FLAGS_MOVED(oop))
{ {
/* this object has migrated to the new heap. /* this object has migrated to the new heap.
* the class field has been updated to the new object * the class field has been updated to the new object
@ -101,12 +101,11 @@ static stix_oop_t move_one (stix_t* stix, stix_oop_t oop)
stix_oop_t tmp; stix_oop_t tmp;
/* calculate the payload size in bytes */ /* calculate the payload size in bytes */
nbytes = (oop->size + oop->extra) * oop->unit; nbytes = (oop->_size + STIX_OBJ_GET_FLAGS_EXTRA(oop)) * STIX_OBJ_GET_FLAGS_UNIT(oop);
nbytes_aligned = STIX_ALIGN (nbytes, STIX_SIZEOF(stix_oop_t)); nbytes_aligned = STIX_ALIGN (nbytes, STIX_SIZEOF(stix_oop_t));
/* allocate space in the new heap */ /* allocate space in the new heap */
tmp = stix_allocheapmem ( tmp = stix_allocheapmem (stix, stix->newheap, STIX_SIZEOF(stix_obj_t) + nbytes_aligned);
stix, stix->newheap, STIX_SIZEOF(stix_obj_t) + nbytes_aligned);
/* allocation here must not fail because /* allocation here must not fail because
* i'm allocating the new space in a new heap for * i'm allocating the new space in a new heap for
@ -121,7 +120,7 @@ static stix_oop_t move_one (stix_t* stix, stix_oop_t oop)
STIX_MEMCPY (tmp, oop, STIX_SIZEOF(stix_obj_t) + nbytes_aligned); STIX_MEMCPY (tmp, oop, STIX_SIZEOF(stix_obj_t) + nbytes_aligned);
/* mark the old object that it has migrated to the new heap */ /* mark the old object that it has migrated to the new heap */
oop->flags |= STIX_OBJ_FLAG_MOVED; STIX_OBJ_SET_FLAGS_MOVED(oop, 1);
/* let the class field of the old object point to the new /* let the class field of the old object point to the new
* object allocated in the new heap. it is returned in * object allocated in the new heap. it is returned in
@ -142,17 +141,17 @@ static stix_uint8_t* scan_new_heap (stix_t* stix, stix_uint8_t* ptr)
stix_oop_t oop; stix_oop_t oop;
oop = (stix_oop_t)ptr; oop = (stix_oop_t)ptr;
nbytes = (oop->size + oop->extra) * oop->unit; nbytes = (oop->_size + STIX_OBJ_GET_FLAGS_EXTRA(oop)) * STIX_OBJ_GET_FLAGS_UNIT(oop);
nbytes_aligned = STIX_ALIGN (nbytes, STIX_SIZEOF(stix_oop_t)); nbytes_aligned = STIX_ALIGN (nbytes, STIX_SIZEOF(stix_oop_t));
oop->_class = move_one (stix, oop->_class); oop->_class = move_one (stix, oop->_class);
if (oop->type == STIX_OBJ_TYPE_OOP) if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_OOP)
{ {
stix_obj_oop_t* xtmp; stix_obj_oop_t* xtmp;
xtmp = (stix_oop_oop_t)oop; xtmp = (stix_oop_oop_t)oop;
for (i = 0; i < oop->size; i++) for (i = 0; i < oop->_size; i++)
{ {
if (STIX_OOP_IS_POINTER(xtmp->slot[i])) if (STIX_OOP_IS_POINTER(xtmp->slot[i]))
xtmp->slot[i] = move_one (stix, xtmp->slot[i]); xtmp->slot[i] = move_one (stix, xtmp->slot[i]);

50
stix/lib/ignite.c Normal file
View File

@ -0,0 +1,50 @@
/*
* $Id$
*
Copyright (c) 2014-2015 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "stix-prv.h"
int stix_ignite (stix_t* stix)
{
STIX_ASSERT (stix->_nil == STIX_NULL);
stix->_nil = stix_allocbytes (stix, STIX_SIZEOF(stix_obj_t));
if (!stix->_nil) return -1;
stix->_nil->_flags = STIX_OBJ_MAKE_FLAGS (STIX_OBJ_TYPE_OOP, STIX_SIZEOF(stix_oop_t), 0, 1, 0);
stix->_nil->_size= 0;
stix->_nil->_class = stix->_nil;
printf ("%lu\n", (unsigned long int)stix->_nil->_flags);
/*stix->_true = stix_instantiate (stix, stix->_true_class, STIX_NULL, 0);
stix->_false = stix_instantiate (stix, stix->_false_class STIX_NULL, 0);
if (!stix->_true || !stix->_false) return -1;*/
return 0;
}

View File

@ -26,7 +26,7 @@
#include "stix-prv.h" #include "stix-prv.h"
static void* alloc_bytes (stix_t* stix, stix_size_t size) void* stix_allocbytes (stix_t* stix, stix_size_t size)
{ {
stix_uint8_t* ptr; stix_uint8_t* ptr;
@ -35,6 +35,8 @@ static void* alloc_bytes (stix_t* stix, stix_size_t size)
{ {
stix_gc (stix); stix_gc (stix);
ptr = stix_allocheapmem (stix, stix->curheap, size); ptr = stix_allocheapmem (stix, stix->curheap, size);
/* TODO: grow heap if ptr is still null. */
} }
return ptr; return ptr;
@ -55,14 +57,11 @@ stix_oop_t stix_allocoopobj (stix_t* stix, stix_oow_t size)
* STIX_SIZEOF(stix_oop_t) will guarantee the starting address * STIX_SIZEOF(stix_oop_t) will guarantee the starting address
* of the allocated space to be an even number. * of the allocated space to be an even number.
* see STIX_OOP_IS_NUMERIC() and STIX_OOP_IS_POINTER() */ * see STIX_OOP_IS_NUMERIC() and STIX_OOP_IS_POINTER() */
hdr = alloc_bytes (stix, STIX_SIZEOF(stix_obj_t) + nbytes_aligned); hdr = stix_allocbytes (stix, STIX_SIZEOF(stix_obj_t) + nbytes_aligned);
if (!hdr) return STIX_NULL; if (!hdr) return STIX_NULL;
hdr->flags = 0; hdr->_flags = STIX_OBJ_MAKE_FLAGS(STIX_OBJ_TYPE_OOP, STIX_SIZEOF(stix_oop_t), 0, 0, 0);
hdr->type = STIX_OBJ_TYPE_OOP; hdr->_size = size;
hdr->extra = 0;
hdr->unit = STIX_SIZEOF(stix_oop_t);
hdr->size = size;
hdr->_class = stix->_nil; hdr->_class = stix->_nil;
while (size > 0) hdr->slot[--size] = stix->_nil; while (size > 0) hdr->slot[--size] = stix->_nil;
@ -88,14 +87,11 @@ static stix_oop_t alloc_numeric_array (stix_t* stix, const void* ptr, stix_oow_t
* STIX_SIZEOF(stix_oop_t) will guarantee the starting address * STIX_SIZEOF(stix_oop_t) will guarantee the starting address
* of the allocated space to be an even number. * of the allocated space to be an even number.
* see STIX_OOP_IS_NUMERIC() and STIX_OOP_IS_POINTER() */ * see STIX_OOP_IS_NUMERIC() and STIX_OOP_IS_POINTER() */
hdr = alloc_bytes (stix, STIX_SIZEOF(stix_obj_t) + nbytes_aligned); hdr = stix_allocbytes (stix, STIX_SIZEOF(stix_obj_t) + nbytes_aligned);
if (!hdr) return STIX_NULL; if (!hdr) return STIX_NULL;
hdr->flags = 0; hdr->_flags = STIX_OBJ_MAKE_FLAGS(type, unit, extra, 0, 0);
hdr->type = type; hdr->_size = len;
hdr->extra = extra;
hdr->unit = unit;
hdr->size = len;
hdr->_class = stix->_nil; hdr->_class = stix->_nil;
if (ptr) if (ptr)
@ -133,8 +129,8 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
{ {
stix_oop_t oop; stix_oop_t oop;
stix_oow_t spec; stix_oow_t spec;
stix_oow_t fixed; stix_oow_t named_instvar;
stix_obj_type_t vtype; stix_obj_type_t indexed_type;
STIX_ASSERT (stix->_nil != STIX_NULL); STIX_ASSERT (stix->_nil != STIX_NULL);
@ -144,57 +140,64 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
STIX_ASSERT (STIX_OOP_IS_SMINT(((stix_oop_class_t)_class)->spec)); STIX_ASSERT (STIX_OOP_IS_SMINT(((stix_oop_class_t)_class)->spec));
spec = STIX_OOP_TO_SMINT(((stix_oop_class_t)_class)->spec); spec = STIX_OOP_TO_SMINT(((stix_oop_class_t)_class)->spec);
fixed = STIX_CLASS_SPEC_FIXED(spec); /* size of the fixed part */ named_instvar = STIX_CLASS_SPEC_NAMED_INSTVAR(spec); /* size of the named_instvar part */
if (!STIX_CLASS_SPEC_ISVAR(spec)) if (STIX_CLASS_SPEC_IS_INDEXED(spec))
{ {
/* named instance variables only. treat it as if it is a indexed_type = STIX_CLASS_SPEC_INDEXED_TYPE(spec);
* variable-pointer class with no variable data */
vtype = STIX_OBJ_TYPE_OOP; if (indexed_type == STIX_OBJ_TYPE_OOP)
vlen = 0; {
if (named_instvar > STIX_MAX_NAMED_INSTVAR ||
vlen > STIX_MAX_INDEXED_COUNT(named_instvar))
{
goto einval;
}
} }
else else
{ {
vtype = STIX_CLASS_SPEC_VTYPE(spec); /* a non-pointer indexed class can't have named instance variables */
if (vtype != STIX_OBJ_TYPE_OOP && fixed > 0) if (named_instvar > 0) goto einval;
{
/* a variable-non-pointer class can't have named instance variables */
stix->errnum = STIX_EINVAL;
return STIX_NULL;
} }
} }
else
{
/* named instance variables only. treat it as if it is an
* indexable class with no variable data */
indexed_type = STIX_OBJ_TYPE_OOP;
vlen = 0;
if (named_instvar > STIX_MAX_NAMED_INSTVAR) goto einval;
}
switch (vtype) switch (indexed_type)
{ {
case STIX_OBJ_TYPE_OOP: case STIX_OBJ_TYPE_OOP:
/* class for a variable object. /* class for a variable object.
* both the fixed-sized part and the variable part are allowed. */ * both the named_instvar-sized part and the variable part are allowed. */
oop = stix_allocoopobj(stix, fixed + vlen); oop = stix_allocoopobj(stix, named_instvar + vlen);
if (!oop) return STIX_NULL; if (!oop) return STIX_NULL;
if (vlen > 0) if (vlen > 0)
{ {
stix_oop_oop_t hdr = (stix_oop_oop_t)oop; stix_oop_oop_t hdr = (stix_oop_oop_t)oop;
STIX_MEMCPY (&hdr->slot[fixed], vptr, vlen * STIX_SIZEOF(stix_oop_t)); STIX_MEMCPY (&hdr->slot[named_instvar], vptr, vlen * STIX_SIZEOF(stix_oop_t));
} }
break; break;
case STIX_OBJ_TYPE_CHAR: case STIX_OBJ_TYPE_CHAR:
/* variable-char class can't have instance variables */ /* variable-char class can't have instance variables */
STIX_ASSERT (fixed == 0);
oop = stix_alloccharobj(stix, vptr, vlen); oop = stix_alloccharobj(stix, vptr, vlen);
if (!oop) return STIX_NULL; if (!oop) return STIX_NULL;
break; break;
case STIX_OBJ_TYPE_UINT8: case STIX_OBJ_TYPE_UINT8:
/* variable-byte class can't have instance variables */ /* variable-byte class can't have instance variables */
STIX_ASSERT (fixed == 0);
oop = stix_allocuint8obj(stix, vptr, vlen); oop = stix_allocuint8obj(stix, vptr, vlen);
if (!oop) return STIX_NULL; if (!oop) return STIX_NULL;
break; break;
case STIX_OBJ_TYPE_UINT16: case STIX_OBJ_TYPE_UINT16:
STIX_ASSERT (fixed == 0);
oop = stix_allocuint16obj(stix, vptr, vlen); oop = stix_allocuint16obj(stix, vptr, vlen);
if (!oop) return STIX_NULL; if (!oop) return STIX_NULL;
break; break;
@ -206,4 +209,9 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
oop->_class = _class; oop->_class = _class;
return oop; return oop;
einval:
stix->errnum = STIX_EINVAL;
return STIX_NULL;
} }

View File

@ -38,8 +38,8 @@
#define STIX_ASSERT(x) assert(x) #define STIX_ASSERT(x) assert(x)
#define STIX_ALIGN(x,y) ((((x) + (y) - 1) / (y)) * (y)) #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 */ /* CLASS */
@ -63,33 +63,43 @@ typedef struct stix_class_t stix_class_t;
typedef struct stix_class_t* stix_oop_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 * 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 * instance variables. The variable part can be specified when the object
* is instantiated if it is variadic. * 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: * The maximum number of named(fixed) instance variables for a class is:
* 2 ^ (BITS-IN-OOW - STIX_OBJ_TYPE_BITS - 1) * 2 ^ (BITS-IN-OOW - STIX_OBJ_TYPE_BITS - 1)
* *
* The number of named instance variables can be greater than 0 if the class * The number of named instance variables can be greater than 0 if the
* is not variable or if it's a variable-pointer class(vtype == STIX_OBJ_TYPE_OOP) * class spec is not indexed or if it's a pointer indexed class
* * (indexed_type == STIX_OBJ_TYPE_OOP)
* See also #stix_obj_type_t.
*/ */
#define STIX_CLASS_SPEC_MAKE(fixed,variadic,vtype) ( \ #define STIX_CLASS_SPEC_MAKE(named_instvar,is_indexed,indexed_type) ( \
(((stix_oow_t)(fixed)) << (STIX_OBJ_TYPE_BITS + 1)) | \ (((stix_oow_t)(named_instvar)) << (STIX_OBJ_TYPE_BITS + 1)) | \
(((stix_oow_t)(vtype)) << 1) | (((stix_oow_t)variadic) & 1) ) (((stix_oow_t)(indexed_type)) << 1) | (((stix_oow_t)is_indexed) & 1) )
/* what is the number of named instance variables? */ /* 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? */ /* is it a user-indexable class?
#define STIX_CLASS_SPEC_ISVAR(spec) ((spec) & 1) * 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? */ /* if so, what is the indexing type? character? pointer? etc? */
#define STIX_CLASS_SPEC_VTYPE(spec) ((spec) & (STIX_LBMASK(stix_oow_t, STIX_OBJ_TYPE_BITS) << 1)) #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 */ /* VM-level macros */
#define STIX_CLASSOF(stix,oop) \ #define STIX_CLASSOF(stix,oop) \
@ -147,6 +157,11 @@ void* stix_allocheapmem (
/* ========================================================================= */ /* ========================================================================= */
/* obj.c */ /* obj.c */
/* ========================================================================= */ /* ========================================================================= */
void* stix_allocbytes (
stix_t* stix,
stix_size_t size
);
stix_oop_t stix_allocoopobj ( stix_oop_t stix_allocoopobj (
stix_t* stix, stix_t* stix,
stix_oow_t size stix_oow_t size
@ -170,6 +185,7 @@ stix_oop_t stix_allocuint16obj (
stix_oow_t len stix_oow_t len
); );
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif

View File

@ -32,15 +32,8 @@
typedef unsigned char stix_uint8_t; typedef unsigned char stix_uint8_t;
typedef unsigned short int stix_uint16_t; typedef unsigned short int stix_uint16_t;
/*typedef unsigned int stix_uint32_t;*/ /*typedef unsigned int stix_uint32_t;*/
#if defined(__MWERKS__) && defined(macintosh)
/* the metrowerks codewarrior compiler produces the 'illegal bitfield declaration'
* if a non-int type is used in the bit-field declaration */
typedef unsigned int stix_uintptr_t;
typedef unsigned int stix_size_t;
#else
typedef unsigned long int stix_uintptr_t; typedef unsigned long int stix_uintptr_t;
typedef unsigned long int stix_size_t; typedef unsigned long int stix_size_t;
#endif
typedef unsigned short int stix_char_t; /* TODO ... wchar_t??? */ typedef unsigned short int stix_char_t; /* TODO ... wchar_t??? */
@ -71,6 +64,16 @@ typedef unsigned short int stix_char_t; /* TODO ... wchar_t??? */
#endif #endif
/* make a low bit mask that can mask off low n bits*/
#define STIX_LBMASK(type,n) (~(~((type)0) << (n)))
/* get 'length' bits starting from the bit at the 'offset' */
#define STIX_GETBITS(type,value,offset,length) \
(((value) >> (offset)) & STIX_LBMASK(type,length))
#define STIX_SETBITS(type,value,offset,length,bits) \
(value = ((value) | (((bits) & STIX_LBMASK(type,length)) << (offset))))
typedef struct stix_mmgr_t stix_mmgr_t; typedef struct stix_mmgr_t stix_mmgr_t;
/** /**
@ -447,11 +450,6 @@ struct stix_t
/* /*
* Object structure * Object structure
*/ */
#define STIX_OBJ_TYPE_BITS 6
#define STIX_OBJ_FLAG_BITS 5
#define STIX_OBJ_EXTRA_BITS 1
#define STIX_OBJ_UNIT_BITS 4
enum stix_obj_type_t enum stix_obj_type_t
{ {
STIX_OBJ_TYPE_OOP, STIX_OBJ_TYPE_OOP,
@ -471,27 +469,22 @@ enum stix_obj_type_t
}; };
typedef enum stix_obj_type_t stix_obj_type_t; typedef enum stix_obj_type_t stix_obj_type_t;
/* KERNEL indicates that the object is known to the virtual
* machine. VM doesn't allow layout changes of such objects. */
enum stix_obj_flag_t
{
STIX_OBJ_FLAG_KERNEL = (1 << 0),
STIX_OBJ_FLAG_HYBRID = (1 << 1),
STIX_OBJ_FLAG_MOVED = (1 << 2)
};
typedef enum stix_obj_flag_t stix_obj_flag_t;
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* Object header structure
*
* _flags:
* type: the type of a payload item. * type: the type of a payload item.
* one of STIX_OBJ_TYPE_OOP, STIX_OBJ_TYPE_CHAR, * one of STIX_OBJ_TYPE_OOP, STIX_OBJ_TYPE_CHAR,
* STIX_OBJ_TYPE_UINT8, STIX_OBJ_TYPE_UINT16 * STIX_OBJ_TYPE_UINT8, STIX_OBJ_TYPE_UINT16
* flags: bitwise-ORed of stix_obj_flag_t * unit: the size of a payload item in bytes.
* extra: 0 or 1. 1 indicates that the payload contains 1 more * extra: 0 or 1. 1 indicates that the payload contains 1 more
* item than the value of the size field. mostly used for a * item than the value of the size field. mostly used for a
* terminating null in a variable-char object. * terminating null in a variable-char object.
* unit: the size of a payload item in bytes. * kernel: 0 or 1. indicates that the object is a kernel object.
* size: the number of payload items in an object. * VM disallows layout changes of a kernel object.
* moved: 0 or 1. used by GC.
*
* _size: the number of payload items in an object.
* it doesn't include the header size. * it doesn't include the header size.
* *
* The total number of bytes occupied by an object can be calculated * The total number of bytes occupied by an object can be calculated
@ -512,12 +505,38 @@ typedef enum stix_obj_flag_t stix_obj_flag_t;
* size calculation and the access to the payload fields become more complex. * size calculation and the access to the payload fields become more complex.
* Therefore, i've dropped the idea. * Therefore, i've dropped the idea.
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
#define STIX_OBJ_FLAGS_TYPE_BITS 6
#define STIX_OBJ_FLAGS_UNIT_BITS 4
#define STIX_OBJ_FLAGS_EXTRA_BITS 1
#define STIX_OBJ_FLAGS_KERNEL_BITS 1
#define STIX_OBJ_FLAGS_MOVED_BITS 1
#define STIX_OBJ_GET_FLAGS_TYPE(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_UNIT_BITS + STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS), STIX_OBJ_FLAGS_TYPE_BITS)
#define STIX_OBJ_GET_FLAGS_UNIT(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS), STIX_OBJ_FLAGS_UNIT_BITS)
#define STIX_OBJ_GET_FLAGS_EXTRA(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS), STIX_OBJ_FLAGS_EXTRA_BITS)
#define STIX_OBJ_GET_FLAGS_KERNEL(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_UNIT_BITS), STIX_OBJ_FLAGS_KERNEL_BITS)
#define STIX_OBJ_GET_FLAGS_MOVED(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, 0, STIX_OBJ_FLAGS_MOVED_BITS)
#define STIX_OBJ_SET_FLAGS_TYPE(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_UNIT_BITS + STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS), STIX_OBJ_FLAGS_TYPE_BITS, v)
#define STIX_OBJ_SET_FLAGS_UNIT(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS), STIX_OBJ_FLAGS_UNIT_BITS, v)
#define STIX_OBJ_SET_FLAGS_EXTRA(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS), STIX_OBJ_FLAGS_EXTRA_BITS, v)
#define STIX_OBJ_SET_FLAGS_KERNEL(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_UNIT_BITS), STIX_OBJ_FLAGS_KERNEL_BITS, v)
#define STIX_OBJ_SET_FLAGS_MOVED(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, 0, STIX_OBJ_FLAGS_MOVED_BITS, v)
/* this macro doesn't check the range of the actual value.
* make sure that the value of each bit fields given fall within the number
* of defined bits */
#define STIX_OBJ_MAKE_FLAGS(t,u,e,k,m) ( \
(((stix_oow_t)(t)) << (STIX_OBJ_FLAGS_UNIT_BITS + STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS)) | \
(((stix_oow_t)(u)) << (STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS)) | \
(((stix_oow_t)(e)) << (STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS)) | \
(((stix_oow_t)(k)) << (STIX_OBJ_FLAGS_MOVED_BITS)) | \
(((stix_oow_t)(m)) << 0) \
)
#define STIX_OBJ_HEADER \ #define STIX_OBJ_HEADER \
stix_oow_t type: STIX_OBJ_TYPE_BITS; \ stix_oow_t _flags; \
stix_oow_t flags: STIX_OBJ_FLAG_BITS; \ stix_oow_t _size; \
stix_oow_t extra: STIX_OBJ_EXTRA_BITS; \
stix_oow_t unit: STIX_OBJ_UNIT_BITS; \
stix_oow_t size; \
stix_oop_t _class stix_oop_t _class
struct stix_obj_t struct stix_obj_t
@ -763,6 +782,15 @@ STIX_EXPORT stix_oop_t stix_instantiate (
stix_oow_t vlen stix_oow_t vlen
); );
/**
* The stix_ignite() function creates key initial objects.
*/
STIX_EXPORT int stix_ignite (
stix_t* stix
);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif